From 825762a404f6412159328ac93cbf7255be8a1ace Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 4 Mar 2019 23:21:26 +0500 Subject: [PATCH 1/3] added handling of bootstrap:modal in a tree --- src/cms_modules/admin.erl | 16 +++++++++++-- src/db.erl | 47 +++++++++++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/src/cms_modules/admin.erl b/src/cms_modules/admin.erl index 9124ae7..3215664 100644 --- a/src/cms_modules/admin.erl +++ b/src/cms_modules/admin.erl @@ -1202,6 +1202,7 @@ event({?MODULE, page, construct}) -> % {{{2 [#{id := P} | _] = Pages, PID = common:q(page_select, P), SelectedBlock = wf:session(selected_block), + common:script("","$('#tree').html('
 loading...
'); "), BlockId=case SelectedBlock of undefined -> "body"; {_B, []} -> "body"; @@ -1519,6 +1520,7 @@ event({?MODULE, block, copy_all_structure, #cms_mfa{id={PID, _},mfa=MFA}=OldBloc coldstrap:close_modal() end; event({?MODULE, block, save, #cms_mfa{id={PID, Block}, sort=S}=OldMFA}) -> % {{{2 + common:script("","$('#tree').html('
 loading...
');"), NewSort= case S of new -> new; @@ -1588,6 +1590,7 @@ event({?MODULE, block, remove_block, B}) -> % {{{2 db:maybe_delete(B), common:script("","$('#tree').save_parent();"), wf:session(selected_block, {Block, Block}), + common:script("","$('#tree').html('
 loading...
');"), wf:wire(#event{postback={?MODULE, page, construct, PID, [Block]}, delegate=?MODULE}), coldstrap:close_modal(); event({?MODULE, user, show}) -> % {{{2 @@ -1882,6 +1885,9 @@ build_list(PID, Block, Lvl, SearchSublink) -> % {{{2 panel -> [Ph,Pb,Pa,Pf|_]=Args, [{I,B} || I <- [Ph,Pb,Pa,Pf], I /= []]; + modal -> + [PB,Mt,Mb,Mf|_]=Args, + [{I,B} || I <- [PB,Mt,Mb,Mf], I /= []]; article -> [Ah,Ab,Af|_]=Args, [{I,B} || I <- [Ah,Ab,Af], I /= []]; @@ -1951,7 +1957,10 @@ copy_subtree(PID, Block, SearchSublink, NewBlockName, Postfix) -> % {{{2 panel -> [A1,A2,A3,A4|A5_N]=Args, NewAgs=lists:append([A1++Postfix,A2++Postfix,A3++Postfix,A4++Postfix], A5_N), - + {M,F,NewAgs}; + modal -> + [A1,A2,A3|A4_N]=Args, + NewAgs=lists:append([A1++Postfix,A2++Postfix,A3++Postfix], A4_N), {M,F,NewAgs}; article -> [A1,A2|A3_N]=Args, @@ -1998,6 +2007,9 @@ extract_mfa_names(#cms_mfa{mfa=MFA}=B) -> % {{{2 panel -> [Ph,Pb,Pa,Pf|_]=Args, [{I,B} || I <- [Ph,Pb,Pa,Pf], I /= []]; + modal -> + [PB,Mt,Mb,Mf|_]=Args, + [{I,B} || I <- [PB,Mt,Mb,Mf], I /= []]; article -> [Ah,Ab,Af|_]=Args, [{I,B} || I <- [Ah,Ab,Af], I /= []]; @@ -2006,4 +2018,4 @@ extract_mfa_names(#cms_mfa{mfa=MFA}=B) -> % {{{2 end; _ -> [{undefined,B}] - end. \ No newline at end of file + end. diff --git a/src/db.erl b/src/db.erl index 6733d04..b30dc31 100644 --- a/src/db.erl +++ b/src/db.erl @@ -670,9 +670,15 @@ get_parent_block(PID, BID, ActionOrBlock) -> % {{{1 case AB of [] -> AF=mnesia:match_object(#cms_mfa{id={PID,'_'},mfa={html5,article,['_','_',BID,'_','_']}, active=true, _='_'}), case AF of - [] -> PB=mnesia:match_object(#cms_mfa{id={PID,'_'},mfa={bootstrap,panel,['_',BID,'_','_','_','_','_','_','_','_']}, active=true, _='_'}), - case PB of - [] -> PH=mnesia:match_object(#cms_mfa{id={PID,'_'},mfa={bootstrap,panel,[BID,'_','_','_','_','_','_','_','_','_']}, active=true, _='_'}), + [] -> MT=mnesia:match_object(#cms_mfa{id={PID,'_'},mfa={bootstrap,modal,['_',BID,'_','_','_','_']}, active=true, _='_'}), + case MT of + [] -> MB=mnesia:match_object(#cms_mfa{id={PID,'_'},mfa={bootstrap,modal,['_','_',BID,'_','_','_']}, active=true, _='_'}), + case MB of + [] -> MF=mnesia:match_object(#cms_mfa{id={PID,'_'},mfa={bootstrap,modal,['_','_','_',BID,'_','_']}, active=true, _='_'}), + case MF of + [] -> PB=mnesia:match_object(#cms_mfa{id={PID,'_'},mfa={bootstrap,panel,['_',BID,'_','_','_','_','_','_','_','_']}, active=true, _='_'}), + case PB of + [] -> PH=mnesia:match_object(#cms_mfa{id={PID,'_'},mfa={bootstrap,panel,[BID,'_','_','_','_','_','_','_','_','_']}, active=true, _='_'}), case PH of [] -> PA=mnesia:match_object(#cms_mfa{id={PID,'_'},mfa={bootstrap,panel,['_','_',BID,'_','_','_','_','_','_','_']}, active=true, _='_'}), case PA of @@ -687,12 +693,18 @@ get_parent_block(PID, BID, ActionOrBlock) -> % {{{1 end; _ -> PA end; - _ -> PH + _ -> PH + end; + _ -> PB end; - _ -> PB + _ -> MF + end; + _ -> MB end; - _ -> AF - end; + _ -> MT + end; + _ -> AF + end; _ -> AB end; _ -> P5 @@ -1335,3 +1347,24 @@ extract_mfa_block_name(#cms_mfa{mfa=MFA}) -> % {{{1 end; _ -> undefined end. + +remove_duplicates() -> % {{{1 +%% @doc "full_delete oldest blocks with the same Id and Sort" + F = fun() -> + FoldFun = + fun(#cms_mfa{id=ID, sort=Sort, mfa=Mfa, updated_at=Upd}, _Acc) -> + case mnesia:match_object(#cms_mfa{id=ID, sort=Sort, _='_'}) of + L when is_list(L), length(L) > 1 -> + [ + if (Cur_mfa#cms_mfa.mfa == Mfa) and (Cur_mfa#cms_mfa.updated_at + mnesia:delete_object(Cur_mfa); + true -> ok + end + || Cur_mfa <- L]; + _ -> ok + end, + ok + end, + mnesia:foldl(FoldFun, ok, cms_mfa) + end, + mnesia:transaction(F). From 4eeffebe48b98730f953b32b348e4a528ef3b64d Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 5 Mar 2019 10:07:57 +0500 Subject: [PATCH 2/3] some optimization on remove block from tree --- src/cms_modules/admin.erl | 12 +++++++----- static/js/bootstrap-treeview.min.js | 4 ++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/cms_modules/admin.erl b/src/cms_modules/admin.erl index 3215664..76f6941 100644 --- a/src/cms_modules/admin.erl +++ b/src/cms_modules/admin.erl @@ -1586,13 +1586,15 @@ event({?MODULE, block, remove, B}) -> % {{{2 [] ); event({?MODULE, block, remove_block, B}) -> % {{{2 - {PID, Block} = B#cms_mfa.id, + {_PID, Block} = B#cms_mfa.id, db:maybe_delete(B), common:script("","$('#tree').save_parent();"), wf:session(selected_block, {Block, Block}), - common:script("","$('#tree').html('
 loading...
');"), - wf:wire(#event{postback={?MODULE, page, construct, PID, [Block]}, delegate=?MODULE}), - coldstrap:close_modal(); + common:script("","$('#tree').remove_active();"), + wf:update(edited_block, #panel{class="collapse"}) + % wf:wire(#event{postback={?MODULE, page, construct, PID, [Block]}, delegate=?MODULE}), + % coldstrap:close_modal() + ; event({?MODULE, user, show}) -> % {{{2 wf:session(history, undefined), CRUD = #crud{ @@ -1873,7 +1875,7 @@ build_list(PID, Block, Lvl, SearchSublink) -> % {{{2 Functions_with_sub_blocks=[dropdown,email_field,password_field,retype_password_field], case {db:get_mfa(PID, Block, true, SearchSublink), (Lvl undefined; - {_, false} -> undefined; + {_, false} -> ?LOG("~nMaxLvl~s", [MaxLvl]), undefined; {L, true} -> SortedList=lists:keysort(#cms_mfa.sort, L), lists:map( diff --git a/static/js/bootstrap-treeview.min.js b/static/js/bootstrap-treeview.min.js index 4477efe..a4c89e1 100644 --- a/static/js/bootstrap-treeview.min.js +++ b/static/js/bootstrap-treeview.min.js @@ -71,6 +71,10 @@ $.fn.extend({ save_parent: function (o) { active_parent=$(".wfid_add_block").val(); + }, + + remove_active: function (o) { + $("a.active").parent().remove(); } }); From 749dcd68d19b3fd7ed2d01260d8b8b22a0b30be8 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 5 Mar 2019 20:34:59 +0500 Subject: [PATCH 3/3] changed language filter --- src/collections/common.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/collections/common.erl b/src/collections/common.erl index 1d40ecd..64e8330 100644 --- a/src/collections/common.erl +++ b/src/collections/common.erl @@ -332,6 +332,7 @@ apply_filters([undefined, undefined, undefined, undefined]) -> % {{{2 apply_filters([K, V, R, T]) -> % {{{2 FilterKV = case K of "" -> true; + "lang" -> index:language([]) == V; K -> wf:to_list(wf:q(wf:to_atom(K))) == wf:to_list(V) end, #cms_user{role=Role} = account:user(), @@ -342,8 +343,7 @@ apply_filters([K, V, R, T]) -> % {{{2 FilterLang = case T of "" -> true; "any" -> true; - Lang -> - wf:to_atom(wf:qs(lang))==wf:to_atom(Lang) + Lang -> index:language([]) == Lang end, FilterKV and FilterRole and FilterLang;