remove Request::post_tab and add Request::http_status
Instead of Reqest::post_tab we use now Request::post_in (pt::Space). Request::http_status will be used instead Request::status, but at the moment is not changed in all places. Request::status has been marked as depracated. While here: - Check for root dir in App and not in FunctionParser, let FunctionParser only log the root dir. - Read post variables after parsing url parameters, this allows winix functions to set limits for post input. - Set limits when parsing input json format, new options added to config: post_max_object_items, post_max_table_items, post_max_all_items, post_max_nested_objects. There are similar options in each winix function (they are in FunctionBase). - Some refactoring in App. - Add config option: log_whole_http_post if true then the whole parsed post input is logged. - Add config option: post_json_max - max length of input stream for parsing json. - Add config option: templates_request_status, default request_status.html this is an ezc template used as [content] when the request status is not 200_ok. - Fix: Sort winix function didn't show items to sort (fix and do some refactoring as well) - Properly sort items in: ImgCrop, Ls, Sort, Upload - Remove ezc templates: err_404.html, err_per_denied.html - now request_status.html is used.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2021, Tomasz Sowa
|
||||
* Copyright (c) 2011-2022, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -65,70 +65,29 @@ bool Sort::HasAccess()
|
||||
|
||||
void Sort::GetDirContent()
|
||||
{
|
||||
// iq.sel_content = false;
|
||||
// iq.WhereParentId(cur->request->dir_tab.back()->id);
|
||||
// db->GetItems(cur->request->item_tab, iq);
|
||||
|
||||
morm::Finder<Item> finder(model_connector);
|
||||
|
||||
finder.
|
||||
select().
|
||||
where().
|
||||
eq(L"parent_id", cur->request->dir_tab.back()->id).
|
||||
get_vector(cur->request->item_tab);
|
||||
raw("order by item.sort_index asc, item.url asc, item.id asc").
|
||||
get_vector(items);
|
||||
|
||||
system->CheckWriteAccessToItems(cur->request->item_tab);
|
||||
system->CheckWriteAccessToItems(items);
|
||||
cur->request->models.Add(L"item_tab", items);
|
||||
}
|
||||
|
||||
|
||||
bool Sort::SortHelper::operator()(size_t t1, size_t t2)
|
||||
Item * Sort::FindItem(long id)
|
||||
{
|
||||
return psort->cur->request->item_tab[t1].id < psort->cur->request->item_tab[t2].id;
|
||||
}
|
||||
|
||||
|
||||
bool Sort::SortFun2(const SortPair & s1, const SortPair & s2)
|
||||
{
|
||||
return s1.id < s2.id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Sort::CreateItemTab()
|
||||
{
|
||||
size_t len = cur->request->item_tab.size();
|
||||
item_tab.resize(len);
|
||||
|
||||
for(size_t i=0 ; i<len ; ++i)
|
||||
item_tab[i] = i;
|
||||
|
||||
std::sort(item_tab.begin() , item_tab.end(), SortHelper(this));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Sort::CreateItemTab2()
|
||||
{
|
||||
PostTab::iterator i2 = cur->request->post_tab.begin();
|
||||
SortPair sp;
|
||||
|
||||
item_tab2.clear();
|
||||
item_tab2.reserve(cur->request->post_tab.size());
|
||||
|
||||
// post_tab is sorted in lexicographical order but we should sort it by numbers
|
||||
|
||||
for( ; i2 != cur->request->post_tab.end() ; ++i2 )
|
||||
for(Item & item : items)
|
||||
{
|
||||
if( pt::is_substr_nc(L"sort", i2->first.c_str()) )
|
||||
{
|
||||
sp.id = Tol(i2->first.c_str() + 4);
|
||||
sp.sort_index = Toi(i2->second);
|
||||
|
||||
item_tab2.push_back(sp);
|
||||
}
|
||||
if( item.id == id )
|
||||
return &item;
|
||||
}
|
||||
|
||||
std::sort(item_tab2.begin(), item_tab2.end(), SortFun2);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +98,6 @@ void Sort::UpdateSortIndex(Item & item, int sort_index)
|
||||
ItemModelData item_model_data;
|
||||
item_model_data.prepare_unique_url = false;
|
||||
|
||||
//if( db->EditSortIndexItemById(item.id, sort_index) == WINIX_ERR_OK )
|
||||
if( item.update(item_model_data, false) )
|
||||
{
|
||||
log << log2
|
||||
@@ -150,42 +108,36 @@ void Sort::UpdateSortIndex(Item & item, int sort_index)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Sort::UpdateSortIndexes()
|
||||
void Sort::UpdateItems()
|
||||
{
|
||||
size_t i1 = 0;
|
||||
size_t i2 = 0;
|
||||
|
||||
while( i1 < item_tab.size() && i2 < item_tab2.size() )
|
||||
if( cur->request->post_in.is_object() )
|
||||
{
|
||||
long id1 = cur->request->item_tab[item_tab[i1]].id;
|
||||
long id2 = item_tab2[i2].id;
|
||||
pt::Space::ObjectType::iterator i2 = cur->request->post_in.value.value_object.begin();
|
||||
|
||||
if( id1 == id2 )
|
||||
for( ; i2 != cur->request->post_in.value.value_object.end() ; ++i2 )
|
||||
{
|
||||
int sort_index = item_tab2[i2].sort_index;
|
||||
Item & item = cur->request->item_tab[item_tab[i1]];
|
||||
if( i2->second->is_wstr() && pt::is_substr_nc(L"sort", i2->first.c_str()) )
|
||||
{
|
||||
long id = Tol(i2->first.c_str() + 4);
|
||||
int sort_index = Toi(*i2->second->get_wstr());
|
||||
|
||||
if( system->HasWriteAccess(item) )
|
||||
UpdateSortIndex(item, sort_index);
|
||||
Item * pitem = FindItem(id);
|
||||
|
||||
++i1;
|
||||
++i2;
|
||||
}
|
||||
else
|
||||
if( id1 < id2 )
|
||||
{
|
||||
++i1;
|
||||
}
|
||||
else
|
||||
{
|
||||
++i2;
|
||||
if( pitem )
|
||||
{
|
||||
if( system->HasWriteAccess(*pitem) )
|
||||
{
|
||||
UpdateSortIndex(*pitem, sort_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Sort::MakePost()
|
||||
{
|
||||
if( cur->request->is_item )
|
||||
@@ -196,13 +148,10 @@ void Sort::MakePost()
|
||||
else
|
||||
{
|
||||
GetDirContent();
|
||||
CreateItemTab();
|
||||
CreateItemTab2();
|
||||
UpdateSortIndexes();
|
||||
UpdateItems();
|
||||
}
|
||||
|
||||
plugin->Call(WINIX_DIR_CONTENT_SORTED, cur->request->dir_tab.back());
|
||||
|
||||
system->RedirectToLastItem();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user