changed: now Request class is a model class - we have fields() method there to map fields for ezc templates (currently only dir_tab)

removed: [dir_tab] ezc statement
changed: Ls winix function loads its own dir_tab container (beforehand it was loaded by [dir_tab] ezc statement)
         it's available by [child_dirs] name
master
Tomasz Sowa 2 years ago
parent 4db421d6c3
commit ebd791a256

@ -88,6 +88,7 @@ App::App()
winix_request.set_cur(&cur);
winix_request.set_session_manager(&session_manager);
winix_request.set_locale(&TemplatesFunctions::locale);
winix_request.set_model_connector(&model_connector);
// //////////////////////////////////

@ -53,6 +53,13 @@ Request::Request()
}
void Request::fields()
{
field(L"", L"dirs", dir_tab);
}
void Request::SetConfig(Config * pconfig)
{
config = pconfig;

@ -50,6 +50,8 @@
#include "outstreams.h"
#include "models.h"
#include "models/winixmodel.h"
namespace Winix
{
@ -62,7 +64,7 @@ class FunctionBase;
struct Request
struct Request : public WinixModel
{
// how many input headers can be put to in_headers struct
static const size_t MAX_INPUT_HEADERS = 32;
@ -360,6 +362,10 @@ struct Request
Request();
void SetConfig(Config * pconfig);
void fields();
void RequestStarts();
void Clear();

@ -50,6 +50,41 @@ Ls::Ls()
}
void Ls::prepare_files()
{
morm::Finder<Item> finder(model_connector);
finder.
select().
where().
eq(L"parent_id", cur->request->dir_tab.back()->id).
neq(L"type", static_cast<int>(Item::dir));
if( cur->request->IsParam(L"ckeditor_browse") )
{
finder.eq(L"content", L"file_type", WINIX_ITEM_FILETYPE_IMAGE);
}
finder.get_vector(item_tab);
}
void Ls::prepare_dirs()
{
dir_tab.clear();
// with parent directory (if exists)
// if dir_tab.size() is equal to 1 then we at the root directory
if( cur->request->dir_tab.size() >= 2 )
{
Item * dir_up = cur->request->dir_tab[cur->request->dir_tab.size()-2];
dir_tab.push_back(dir_up);
}
system->dirs.GetDirChilds(cur->request->dir_tab.back()->id, dir_tab);
}
void Ls::MakeGet()
{
// !! IMPROVE ME
@ -61,33 +96,15 @@ void Ls::MakeGet()
if( !cur->request->is_item )
{
// DbItemQuery iq;
//
// iq.sel_content = false;
//
// iq.WhereParentId(cur->request->dir_tab.back()->id);
// iq.WhereType(Item::dir, false);
morm::Finder<Item> finder(model_connector);
finder.
select().
where().
eq(L"parent_id", cur->request->dir_tab.back()->id).
neq(L"type", static_cast<int>(Item::dir));
if( cur->request->IsParam(L"ckeditor_browse") )
{
//iq.WhereFileType(WINIX_ITEM_FILETYPE_IMAGE);
//db->GetItems(cur->request->item_tab, iq);
finder.eq(L"content", L"file_type", WINIX_ITEM_FILETYPE_IMAGE);
}
// else
// {
// //db->GetItems(cur->request->item_tab, iq);
// }
finder.get_vector(cur->request->item_tab);
prepare_files();
prepare_dirs();
cur->request->models.Add(L"items", item_tab);
cur->request->models.Add(L"child_dirs", dir_tab);
// IMPROVEME this will be put by a generic method from winix
// if output is html
cur->request->models.Add(L"request", cur->request);
}
}

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* Copyright (c) 2010-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -55,7 +55,11 @@ public:
private:
std::vector<Item> item_tab;
std::vector<Item*> dir_tab;
void prepare_files();
void prepare_dirs();
};

@ -7,14 +7,14 @@
<div class="uk-margin">
<ul class="uk-breadcrumb">
[for dir_tab]
[for request.dirs]
<li>
<a href="[doc_base_url][dir_tab_link]ls/ckeditor_browse/CKEditor:itemcontent/CKEditorFuncNum:[ls_ckeditor_funnum_browse]">
[if cmp dir_tab_url ""]
<a href="[doc_base_url][request.dirs.link]ls/ckeditor_browse/CKEditor:itemcontent/CKEditorFuncNum:[ls_ckeditor_funnum_browse]">
[if cmp request.dirs.url ""]
[# !! IMPROVE ME it would be better to have a flag of some kind to indicate that this is a root dir]
{ls_root_dir_name}
[else]
[dir_tab_url]
[request.dirs.url]
[end]
</a>
</li>
@ -25,16 +25,16 @@
<div class="uk-flex uk-margin-medium">
<div class="uk-width-1-4">
[if dir_childs_tab "with_parent"]
[if child_dirs]
<ul class="uk-list uk-list-disc uk-list-collapse">
[for dir_childs_tab "with_parent"]
[for child_dirs]
<li>
[if dir_childs_is_parent]
[if child_dirs.is_parent_for_current_dir]
[# make sure the name of the textarea in fun_ckeditor.html is called: itemcontent]
[# is it needed?]
<a href="[doc_base_url][dir_parent]ls/ckeditor_browse/CKEditor:itemcontent/CKEditorFuncNum:[ls_ckeditor_funnum_browse]">../</a>
[else]
<a href="[doc_base_url][dir][dir_childs_tab_url]/ls/ckeditor_browse/CKEditor:itemcontent/CKEditorFuncNum:[ls_ckeditor_funnum_browse]">[dir_childs_tab_url]/</a>
<a href="[doc_base_url][dir][child_dirs.url]/ls/ckeditor_browse/CKEditor:itemcontent/CKEditorFuncNum:[ls_ckeditor_funnum_browse]">[child_dirs.url]/</a>
[end]
</li>
[end]
@ -45,12 +45,12 @@
<div class="">
[if item_tab]
[if items]
<ul class="uk-list uk-list-collapse" data-uk-grid>
[for item_tab]
<li><a href="javascript:select('[item_tab_link]')"><img data-src="[item_tab_link]/-/thumb" alt="[item_tab_subject]" height="120" data-uk-img></a></li>
[for items]
<li><a href="javascript:select('[items.link]')"><img data-src="[items.link]/-/thumb" alt="[items.subject]" height="120" data-uk-img></a></li>
[end]
</ul>
@ -69,11 +69,7 @@
[if winix_function_param_is "l"]
[# loading dir childs table with a parent directory]
[# now the parameter can be passed directly to if-one]
[dir_childs_tab "with_parent"]
[if one dir_childs_tab item_tab]
[if one child_dirs items]
<table class="uk-table uk-table-divider uk-table-small uk-table-justify uk-table-responsive">
<tr>
@ -84,29 +80,29 @@
<th>{ls_name}</th>
</tr>
[for dir_childs_tab]
[for child_dirs]
<tr>
<td>d</td>
<td>[dir_childs_tab_privileges]</td>
<td>[dir_childs_tab_user]</td>
<td>[dir_childs_tab_group]</td>
<td>[child_dirs_privileges]</td>
<td>[child_dirs_user]</td>
<td>[child_dirs_group]</td>
<td>
[if dir_childs_is_parent]
[if child_dirs.is_parent_for_current_dir]
<a href="[doc_base_url][dir_parent_without_slash][if winix_function_param_is "dirls"]/ls/l/dirls[end]">../</a>
[else]
<a href="[doc_base_url][dir][dir_childs_tab_url][if winix_function_param_is "dirls"]/ls/l/dirls[end]">[dir_childs_tab_url]/</a>
<a href="[doc_base_url][dir][child_dirs.url][if winix_function_param_is "dirls"]/ls/l/dirls[end]">[child_dirs.url]/</a>
[end]
</td>
</tr>
[end]
[for item_tab]
[for items]
<tr>
<td>[if item_tab_type_is_symlink]l[else][if item_tab_has_static_file]s[else]-[end][end]</td>
<td>[item_tab_privileges]</td>
<td>[item_tab_user]</td>
<td>[item_tab_group]</td>
<td><a href="[doc_base_url][dir][item_tab_url]">[item_tab_url]</a>[if item_tab_type_is_symlink] -> [item_tab_link_to][end]</td>
<td>[if items_type_is_symlink]l[else][if items_has_static_file]s[else]-[end][end]</td>
<td>[items_privileges]</td>
<td>[items_user]</td>
<td>[items_group]</td>
<td><a href="[doc_base_url][dir][items.url]">[items.url]</a>[if items_type_is_symlink] -> [items_link_to][end]</td>
</tr>
[end]
</table>
@ -115,27 +111,24 @@
[else]
[# loading dir childs table with a parent directory]
[dir_childs_tab "with_parent"]
[if dir_childs_tab]
[if child_dirs]
<ul class="uk-list uk-list-disc uk-list-collapse">
[for dir_childs_tab]
[for child_dirs]
<li>
[if dir_childs_is_parent]
[if child_dirs.is_parent_for_current_dir]
<a href="[doc_base_url][dir_parent_without_slash][if winix_function_param_is "dirls"]/ls/dirls[end]">../</a>
[else]
<a href="[doc_base_url][dir][dir_childs_tab_url][if winix_function_param_is "dirls"]/ls/dirls[end]">[dir_childs_tab_url]/</a>
<a href="[doc_base_url][dir][child_dirs.url][if winix_function_param_is "dirls"]/ls/dirls[end]">[child_dirs.url]/</a>
[end]
</li>
[end]
</ul>
[end]
[# !! IMPROVE ME those two lists (above and below) can be combined together]
[if item_tab]
[if items]
<ul class="uk-list uk-list-disc uk-list-collapse">
[for item_tab]
<li><a href="[doc_base_url][dir][item_tab_url]">[item_tab_url]</a></li>
[for items]
<li><a href="[doc_base_url][dir][items.url]">[items.url]</a></li>
[end]
</ul>
[end]

@ -70,6 +70,9 @@ void Item::fields()
field(L"is", &Item::is);
field(L"dir_link", &Item::dir_link);
field(L"link", &Item::link);
field(L"is_parent_for_current_dir", &Item::is_parent_for_current_dir);
field(L"is_current_dir", &Item::is_current_dir);
field(L"is_root", &Item::is_root);
// may we should add a method setTypeFromInt(int t)?
@ -325,6 +328,41 @@ void Item::link(Ezc::FunInfo<HtmlTextStream> & env)
}
void Item::is_parent_for_current_dir(Ezc::FunInfo<HtmlTextStream> & env)
{
Request * req = get_request();
if( req )
{
if( req->dir_tab.size() > 1 )
{
env.res = (id == req->dir_tab[req->dir_tab.size() - 2]->id);
}
}
}
void Item::is_current_dir(Ezc::FunInfo<HtmlTextStream> & env)
{
Request * req = get_request();
if( req )
{
env.res = (id == req->dir_tab.back()->id);
}
}
// rename to is_root_dir
void Item::is_root(Ezc::FunInfo<HtmlTextStream> & env)
{
Request * req = get_request();
if( req )
{
// add a test whether this is a directory (not a file or a symlink)
env.res = (parent_id == -1);
}
}

@ -190,6 +190,9 @@ public:
void is(Ezc::FunInfo<HtmlTextStream> & env);
void dir_link(Ezc::FunInfo<HtmlTextStream> & env);
void link(Ezc::FunInfo<HtmlTextStream> & env);
void is_parent_for_current_dir(Ezc::FunInfo<HtmlTextStream> & env);
void is_current_dir(Ezc::FunInfo<HtmlTextStream> & env);
void is_root(Ezc::FunInfo<HtmlTextStream> & env);
protected:

@ -204,7 +204,7 @@ void dir_level_is(Info & i)
/*
static std::vector<Item*> dir_childs_table;
static size_t dir_childs_index;
// cur->request->id is never 0 and we can start dir_childs_reqid from 0
@ -298,12 +298,12 @@ void dir_childs_tab_group(Info & i)
i.out << group_id;
}
}
*/
/*
static size_t dir_index;
@ -333,7 +333,6 @@ void dir_tab_link(Info & i)
}
}
void dir_tab_is_root(Info & i)
{
i.res = (dir_index == 0);
@ -345,6 +344,7 @@ void dir_tab_subject(Info & i)
if( dir_index < cur->request->dir_tab.size() )
i.out << cur->request->dir_tab[dir_index]->subject;
}
*/
void dir_last_link_to(Info & i)

@ -274,18 +274,22 @@ void Templates::CreateFunctions()
ezc_functions.Insert("dir_has_parents", dir_has_parents);
ezc_functions.Insert("dir_level_is", dir_level_is);
/*
ezc_functions.Insert("dir_childs_tab", dir_childs_tab);
ezc_functions.Insert("dir_childs_is_parent", dir_childs_is_parent);
ezc_functions.Insert("dir_childs_tab_url", dir_childs_tab_url);
ezc_functions.Insert("dir_childs_tab_privileges", dir_childs_tab_privileges);
ezc_functions.Insert("dir_childs_tab_user", dir_childs_tab_user);
ezc_functions.Insert("dir_childs_tab_group", dir_childs_tab_group);
*/
/*
ezc_functions.Insert("dir_tab", dir_tab);
ezc_functions.Insert("dir_tab_url", dir_tab_url);
ezc_functions.Insert("dir_tab_link", dir_tab_link);
ezc_functions.Insert("dir_tab_subject", dir_tab_subject);
ezc_functions.Insert("dir_tab_is_root", dir_tab_is_root);
*/
ezc_functions.Insert("dir_last_link_to", dir_last_link_to);
ezc_functions.Insert("dir_last_is_link_redirect", dir_last_is_link_redirect);

@ -164,18 +164,22 @@ namespace TemplatesFunctions
void dir_has_parents(Info & i);
void dir_level_is(Info & i);
/*
void dir_childs_tab(Info & i);
void dir_childs_is_parent(Info & i);
void dir_childs_tab_url(Info & i);
void dir_childs_tab_privileges(Info & i);
void dir_childs_tab_user(Info & i);
void dir_childs_tab_group(Info & i);
*/
/*
void dir_tab(Info & i);
void dir_tab_url(Info & i);
void dir_tab_link(Info & i);
void dir_tab_subject(Info & i);
void dir_tab_is_root(Info & i);
*/
void dir_last_link_to(Info &);
void dir_last_is_link_redirect(Info & i);

Loading…
Cancel
Save