mirror of
https://github.com/openclassify/openclassify.git
synced 2026-02-08 22:36:06 -06:00
Merge pull request #117 from openclassify/vedat
#493 category admin panel edited
This commit is contained in:
commit
ad0d372eef
@ -15,7 +15,7 @@ class VisiosoftModuleCatsCreateCategoryStream extends Migration
|
|||||||
'title_column' => 'name',
|
'title_column' => 'name',
|
||||||
'translatable' => true,
|
'translatable' => true,
|
||||||
'versionable' => false,
|
'versionable' => false,
|
||||||
'trashable' => false,
|
'trashable' => true,
|
||||||
'searchable' => false,
|
'searchable' => false,
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
];
|
];
|
||||||
|
|||||||
@ -14,10 +14,15 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
{% set parent_url = url('admin/cats?cat='~parent.parent_category_id) %}
|
{% set parent_url = url('admin/cats?cat='~parent.parent_category_id) %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<ol class="breadcrumb">
|
||||||
|
{% for parnt in category_parents_name(app.request.get('cat'))|reverse %}
|
||||||
|
<li class="breadcrumb-item"><a><b>{{ parnt }}</b></a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ol>
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div id="buttons">
|
<div id="buttons">
|
||||||
<a class="btn btn-md btn-warning " href="{{ parent_url }}">
|
<a class="btn btn-md btn-warning " href="{{ parent_url }}">
|
||||||
<i class="fa fa-arrow-left"></i> Go To Parent ../<b><u>{{ parent.name }}</u></b>
|
<i class="fa fa-arrow-left"></i> Go To Parent
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,33 +1,7 @@
|
|||||||
<?php namespace Visiosoft\CatsModule\Category;
|
<?php namespace Visiosoft\CatsModule\Category;
|
||||||
|
|
||||||
use Anomaly\Streams\Platform\Entry\EntryCollection;
|
use Anomaly\Streams\Platform\Entry\EntryCollection;
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
class CategoryCollection extends EntryCollection
|
class CategoryCollection extends EntryCollection
|
||||||
{
|
{
|
||||||
public function deleteCat($id)
|
|
||||||
{
|
|
||||||
$adv = CategoryModel::query()->find($id);
|
|
||||||
$adv->deleted_at = Carbon::now();
|
|
||||||
$adv->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function subCatDelete($id)
|
|
||||||
{
|
|
||||||
$counter = 0;
|
|
||||||
|
|
||||||
for ($i = 0; $i <= $counter; $i++) {
|
|
||||||
$data = CategoryModel::query()
|
|
||||||
->where('cats_category.parent_category_id', $id)
|
|
||||||
->where('cats_category.deleted_at', null)
|
|
||||||
->select('cats_category.id', 'cats_category.parent_category_id')
|
|
||||||
->first();
|
|
||||||
if ($data != "") {
|
|
||||||
$id = $data['id'];
|
|
||||||
$counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$delete = new CategoryCollection();
|
|
||||||
$delete = $delete->deleteCat($id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
|
|||||||
return CategoryModel::query()->where('cats_category.id', $id)->first();
|
return CategoryModel::query()->where('cats_category.id', $id)->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getParentCats($id, $type = null, $subCatDeepCount = 7)
|
public function getParentCats($id, $type = null)
|
||||||
{
|
{
|
||||||
$cat = $this->getCat($id);
|
$cat = $this->getCat($id);
|
||||||
$catNames = array();
|
$catNames = array();
|
||||||
@ -24,6 +24,8 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
|
|||||||
for ($i = 0; $i < 7; $i++) {
|
for ($i = 0; $i < 7; $i++) {
|
||||||
$parCat = $this->getCat($subCat);
|
$parCat = $this->getCat($subCat);
|
||||||
if ($parCat->parent_category_id == "") {
|
if ($parCat->parent_category_id == "") {
|
||||||
|
if ($type == "add_main")
|
||||||
|
$catNames[] = $parCat->name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$catNames[] = $parCat->name;
|
$catNames[] = $parCat->name;
|
||||||
@ -44,7 +46,7 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
|
|||||||
public function getCatLevel($id)
|
public function getCatLevel($id)
|
||||||
{
|
{
|
||||||
//count parent and itself
|
//count parent and itself
|
||||||
return count($this->getParentCats($id))+1;
|
return count($this->getParentCats($id)) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSubCategories($id, $get = null)
|
public function getSubCategories($id, $get = null)
|
||||||
@ -96,12 +98,12 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
|
|||||||
$join->on('cats_category.id', '=', 'cats_category_translations.entry_id');
|
$join->on('cats_category.id', '=', 'cats_category_translations.entry_id');
|
||||||
$join->where('cats_category_translations.locale', '=', Request()->session()->get('_locale'));
|
$join->where('cats_category_translations.locale', '=', Request()->session()->get('_locale'));
|
||||||
});
|
});
|
||||||
$cats = $cats->select('cats_category.*','cats_category_translations.name as name');
|
$cats = $cats->select('cats_category.*', 'cats_category_translations.name as name');
|
||||||
$cats = $cats->orderBy('id', 'DESC')
|
$cats = $cats->orderBy('id', 'DESC')
|
||||||
->get();
|
->get();
|
||||||
foreach ($cats as $cat) {
|
foreach ($cats as $cat) {
|
||||||
$link = '';
|
$link = '';
|
||||||
$parents = $this->getParentCats($cat->id, null, 2);
|
$parents = $this->getParentCats($cat->id, null);
|
||||||
krsort($parents);
|
krsort($parents);
|
||||||
foreach ($parents as $key => $parent) {
|
foreach ($parents as $key => $parent) {
|
||||||
if ($key == 0) {
|
if ($key == 0) {
|
||||||
|
|||||||
@ -63,4 +63,15 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
|
|||||||
{
|
{
|
||||||
return $this->model->get();
|
return $this->model->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function DeleteCategories($id)
|
||||||
|
{
|
||||||
|
$sub_categories = $this->model->getAllSubCategories($id);
|
||||||
|
if (count($sub_categories)) {
|
||||||
|
$this->model
|
||||||
|
->whereIn('id', array_merge($sub_categories, [$id]))
|
||||||
|
->delete();
|
||||||
|
} else
|
||||||
|
$this->model->find($id)->delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,4 +19,6 @@ interface CategoryRepositoryInterface extends EntryRepositoryInterface
|
|||||||
public function findBySlug($slug);
|
public function findBySlug($slug);
|
||||||
|
|
||||||
public function getCategories();
|
public function getCategories();
|
||||||
|
|
||||||
|
public function DeleteCategories($id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,9 @@ class CategoryTableBuilder extends TableBuilder
|
|||||||
* @var array|string
|
* @var array|string
|
||||||
*/
|
*/
|
||||||
protected $buttons = [
|
protected $buttons = [
|
||||||
'edit',
|
'edit' => [
|
||||||
|
'href' => '/admin/cats/edit/{entry.id}?parent={entry.parent_category_id}'
|
||||||
|
],
|
||||||
'add_sub_category' => [
|
'add_sub_category' => [
|
||||||
'icon' => 'fa fa-caret-square-o-down',
|
'icon' => 'fa fa-caret-square-o-down',
|
||||||
'type' => 'success',
|
'type' => 'success',
|
||||||
@ -50,7 +52,7 @@ class CategoryTableBuilder extends TableBuilder
|
|||||||
'delete' => [
|
'delete' => [
|
||||||
'icon' => 'fa fa-trash',
|
'icon' => 'fa fa-trash',
|
||||||
'type' => 'danger',
|
'type' => 'danger',
|
||||||
'href' => '/admin/cats/category/delete/{entry.id}'
|
'href' => '/admin/cats/category/delete/{entry.id}?parent={entry.parent_category_id}'
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
<?php namespace Visiosoft\CatsModule;
|
<?php namespace Visiosoft\CatsModule;
|
||||||
|
|
||||||
use Anomaly\Streams\Platform\Addon\Plugin\Plugin;
|
use Anomaly\Streams\Platform\Addon\Plugin\Plugin;
|
||||||
|
use Visiosoft\CatsModule\Category\CategoryModel;
|
||||||
use Visiosoft\CatsModule\Category\Command\GetCategoryName;
|
use Visiosoft\CatsModule\Category\Command\GetCategoryName;
|
||||||
use Visiosoft\CatsModule\Category\Command\GetCategoryDetail;
|
use Visiosoft\CatsModule\Category\Command\GetCategoryDetail;
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ class CatsModulePlugin extends Plugin
|
|||||||
|
|
||||||
return $ad;
|
return $ad;
|
||||||
}
|
}
|
||||||
),new \Twig_SimpleFunction(
|
), new \Twig_SimpleFunction(
|
||||||
'category_detail',
|
'category_detail',
|
||||||
function ($id) {
|
function ($id) {
|
||||||
|
|
||||||
@ -33,6 +34,12 @@ class CatsModulePlugin extends Plugin
|
|||||||
|
|
||||||
return $ad;
|
return $ad;
|
||||||
}
|
}
|
||||||
|
), new \Twig_SimpleFunction(
|
||||||
|
'category_parents_name',
|
||||||
|
function ($id) {
|
||||||
|
$category_model = new CategoryModel();
|
||||||
|
return $category_model->getParentCats($id,'add_main');
|
||||||
|
}
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -184,4 +184,31 @@ class CatsModuleServiceProvider extends AddonServiceProvider
|
|||||||
// Use method injection or commands to bring in services.
|
// Use method injection or commands to bring in services.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getOverrides()
|
||||||
|
{
|
||||||
|
$request = app('Illuminate\Http\Request');
|
||||||
|
$view = $request->get('view');
|
||||||
|
|
||||||
|
if ($request->segment(2) === $this->addon->getSlug() && $view !== 'table' and $request->path() == "admin/cats") {
|
||||||
|
$sections = [
|
||||||
|
'category' => [
|
||||||
|
'buttons' => [
|
||||||
|
'new_category' => [
|
||||||
|
'href' => '/admin/cats/create?parent='.$request->cat
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'placeholderforsearch' => [
|
||||||
|
'buttons' => [
|
||||||
|
'new_placeholderforsearch',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$this->addon->setSections($sections);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::getOverrides();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ use Illuminate\Http\Request;
|
|||||||
use Sunra\PhpSimple\HtmlDomParser;
|
use Sunra\PhpSimple\HtmlDomParser;
|
||||||
use Visiosoft\CatsModule\Category\CategoryCollection;
|
use Visiosoft\CatsModule\Category\CategoryCollection;
|
||||||
use Visiosoft\CatsModule\Category\CategoryModel;
|
use Visiosoft\CatsModule\Category\CategoryModel;
|
||||||
|
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
|
||||||
use Visiosoft\CatsModule\Category\Form\CategoryFormBuilder;
|
use Visiosoft\CatsModule\Category\Form\CategoryFormBuilder;
|
||||||
use Visiosoft\CatsModule\Category\Table\CategoryTableBuilder;
|
use Visiosoft\CatsModule\Category\Table\CategoryTableBuilder;
|
||||||
use Anomaly\Streams\Platform\Http\Controller\AdminController;
|
use Anomaly\Streams\Platform\Http\Controller\AdminController;
|
||||||
@ -58,9 +59,8 @@ class CategoryController extends AdminController
|
|||||||
if ($form->hasFormErrors()) {
|
if ($form->hasFormErrors()) {
|
||||||
return $this->redirect->to('/admin/cats/create');
|
return $this->redirect->to('/admin/cats/create');
|
||||||
}
|
}
|
||||||
if($parent_id != "")
|
if ($parent_id != "") {
|
||||||
{
|
return $this->redirect->to('/admin/cats?cat=' . $parent_id);
|
||||||
return $this->redirect->to('/admin/cats?cat='.$parent_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->redirect->to('/admin/cats');
|
return $this->redirect->to('/admin/cats');
|
||||||
@ -89,6 +89,12 @@ class CategoryController extends AdminController
|
|||||||
if ($form->hasFormErrors()) {
|
if ($form->hasFormErrors()) {
|
||||||
return $this->redirect->back();
|
return $this->redirect->back();
|
||||||
}
|
}
|
||||||
|
$parent = $request->parent_category;
|
||||||
|
if ($parent != "") {
|
||||||
|
return $this->redirect->to('/admin/cats?cat=' . $parent);
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
return $this->redirect->to('/admin/cats');
|
||||||
} else {
|
} else {
|
||||||
$form->setFields(['name']);
|
$form->setFields(['name']);
|
||||||
$nameField = HTMLDomParser::str_get_html($form->render($id)->getContent());
|
$nameField = HTMLDomParser::str_get_html($form->render($id)->getContent());
|
||||||
@ -103,26 +109,25 @@ class CategoryController extends AdminController
|
|||||||
return $this->view->make('visiosoft.module.cats::cats/admin-cat', compact('nameField'))->with('id', $id);
|
return $this->view->make('visiosoft.module.cats::cats/admin-cat', compact('nameField'))->with('id', $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete(CategoryCollection $categoryCollection, CategoryModel $categoryModel, $id)
|
public function delete(CategoryRepositoryInterface $categoryRepository, Request $request, CategoryModel $categoryModel, $id)
|
||||||
{
|
{
|
||||||
|
ini_set('max_execution_time', 0);
|
||||||
echo "<div style='background-image:url(" . $this->dispatch(new MakeImageInstance('visiosoft.theme.default::images/loading_anim.gif', 'img'))->url() . ");
|
echo "<div style='background-image:url(" . $this->dispatch(new MakeImageInstance('visiosoft.theme.default::images/loading_anim.gif', 'img'))->url() . ");
|
||||||
background-repeat:no-repeat;
|
background-repeat:no-repeat;
|
||||||
background-size: 300px;
|
background-size: 300px;
|
||||||
background-position:center;
|
background-position:center;
|
||||||
text-align:center;
|
text-align:center;
|
||||||
width:98%;
|
width:98%;
|
||||||
height:100%;
|
height:100%;
|
||||||
padding-left: 20px;'><h3>" . trans('visiosoft.module.cats::field.please_wait') . "</h3></div>";
|
padding-left: 20px;'><h3>" . trans('visiosoft.module.cats::field.please_wait') . "</h3></div>";
|
||||||
$Find_Categories = $categoryModel
|
|
||||||
->where('deleted_at', null)
|
|
||||||
->find($id);
|
|
||||||
if ($Find_Categories != "") {
|
|
||||||
$categoryCollection->subCatDelete($id);
|
|
||||||
header("Refresh:0");
|
|
||||||
} else {
|
|
||||||
$categoryModel->find($id)->delete();
|
|
||||||
return redirect('admin/cats')->with('success', ['Category and related sub-categories deleted successfully.']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$categoryRepository->DeleteCategories($id);
|
||||||
|
|
||||||
|
if ($request->parent == "")
|
||||||
|
return redirect('admin/cats')->with('success', ['Category and related sub-categories deleted successfully.']);
|
||||||
|
else
|
||||||
|
return redirect('admin/cats?cat=' . $request->parent)->with('success', ['Category and related sub-categories deleted successfully.']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user