-
-
-
{{child.title}}
-
- Additional info
+
+
+ Route: {{child.route}}
-
\ No newline at end of file
+
+
+
\ No newline at end of file
diff --git a/dashboard/menu/menu.component.ts b/dashboard/menu/menu.component.ts
index 61f88613..bcdb8df8 100644
--- a/dashboard/menu/menu.component.ts
+++ b/dashboard/menu/menu.component.ts
@@ -14,6 +14,8 @@ import {AlertModal} from '../../utils/modal/alert';
import {CheckMenuItem, MenuItem} from '../../sharedComponents/menu';
import {SearchInputComponent} from '../../sharedComponents/search-input/search-input.component';
+declare var UIkit;
+
@Component({
selector: 'menuSelector',
templateUrl: './menu.component.html',
@@ -23,28 +25,21 @@ export class MenuComponent implements OnInit {
@ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent;
@ViewChild('editModal') editModal: AlertModal;
@ViewChild('deleteModal') deleteModal: AlertModal;
- private selectedMenuItems: string[] = [];
-
- public checkboxes: CheckMenuItem[] = [];
-
- // public menuItems: MenuItem[] = [];
-
- // public rootMenuForm: FormGroup;
public activeRootMenu: string;
+ private index: number;
public menuItemForm: FormGroup;
public rootMenuItems = [];
public menuItems = [];
public allPages = [];
- public keyword = '';
+ public selectedMenuItem: string;
+ public isChild: boolean = false;
public communities: Portal[] = [];
public portal: string;
- public properties: EnvProperties = properties;
-
public newPageWindowOpen: boolean = false;
public showLoading = true;
public isPortalAdministrator = null;
@@ -53,7 +48,12 @@ export class MenuComponent implements OnInit {
{label: 'Internal Link', value: 'internal'},
{label: 'External Link', value: 'external'}
]
- public selectedKeyword: string;
+
+ public keyword: string = '';
+ public selectedKeyword: string = '';
+ private searchText: string = '';
+
+ public properties: EnvProperties = properties;
private subscriptions: any[] = [];
constructor(private element: ElementRef, private route: ActivatedRoute,
@@ -65,8 +65,11 @@ export class MenuComponent implements OnInit {
ngOnInit() {
this.filterForm = this._fb.group({
keyword: [''],
- status: ['resources', Validators.required]
});
+ this.subscriptions.push(this.filterForm.get('keyword').valueChanges.subscribe(value => {
+ this.searchText = value.toLowerCase();
+ this.applyFilters();
+ }));
this.userManagementService.getUserInfo().subscribe(user => {
this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
if (this.route.snapshot.data.portal) {
@@ -97,11 +100,9 @@ export class MenuComponent implements OnInit {
this.subscriptions.push(
this._helpContentService.getMenuItems(this.portal).subscribe(
data => {
- console.log(data);
this.rootMenuItems = data;
if(data && data.length > 0) {
this.activeRootMenu = data[0]['_id'];
- console.log(this.activeRootMenu);
}
},
err => console.error("Server error fetching menu items: ", err)
@@ -130,82 +131,83 @@ export class MenuComponent implements OnInit {
);
}
- public newRootMenu() {
+ public newPageWindow() {
+ this.newPageWindowOpen = !this.newPageWindowOpen;
+ }
+
+ public newMenuItem(isChild: boolean = false) {
this.menuItemForm = this._fb.group({
- id: this._fb.control(""),
+ _id: this._fb.control(""),
title: this._fb.control("",Validators.required),
type: this._fb.control(""),
route: this._fb.control(""),
url: this._fb.control(""),
isEnabled: this._fb.control(""),
+ parentItemId: this._fb.control(isChild ? this.activeRootMenu : null)
});
- this.menuItemsModalOpen('Create Root Menu', 'Save Changes');
+ this.isChild = isChild;
+ this.menuItemsModalOpen('Create Menu Item', 'Create');
}
- public editRootMenu() {
+ public editMenuItem(menuItem: MenuItem, isChild: boolean = false) {
this.menuItemForm = this._fb.group({
- id: this._fb.control("id"),
- title: this._fb.control("Resources",Validators.required),
- type: this._fb.control("",Validators.required),
- route: this._fb.control("noNeed"),
- url: this._fb.control("noNeed"),
- isEnabled: this._fb.control("enabled",Validators.required),
+ _id: this._fb.control(menuItem['_id']),
+ title: this._fb.control(menuItem.title,Validators.required),
+ type: this._fb.control(menuItem['type']),
+ route: this._fb.control(menuItem.route),
+ url: this._fb.control(menuItem.url),
+ parentItemId: this._fb.control(menuItem['parentItemId'])
});
- this.menuItemsModalOpen('Edit Root Menu', 'Save Changes');
+ this.isChild = isChild;
+ if(this.isChild) {
+ this.index = this.getActiveRootItem(this.activeRootMenu).items.findIndex(value => value._id === menuItem['_id']);
+ } else {
+ this.index = this.rootMenuItems.findIndex(value => value._id === menuItem['_id']);
+ }
+ this.menuItemsModalOpen('Edit Menu Item', 'Save Changes');
}
- public deleteRootMenu() {
- console.log('Delete root menu');
- }
- public getSelectedMenuItems(): string[] {
- return this.checkboxes.filter(menuItem => menuItem.checked == true).map(checkedMenuItem => checkedMenuItem.menuItem).map(res => res.id);
+ public confirmDeleteMenuItem(id: string, isChild: boolean = false) {
+ this.selectedMenuItem = id;
+ this.isChild = isChild;
+ this.confirmModalOpen();
}
- public confirmDeleteSelectedMenuItems() {
- this.selectedMenuItems = this.getSelectedMenuItems();
- this.confirmModalOpen();
- }
-
private confirmModalOpen() {
this.deleteModal.cancelButton = true;
this.deleteModal.okButton = true;
this.deleteModal.alertTitle = 'Delete Confirmation';
- this.deleteModal.message = 'Are you sure you want to delete the selected menu item(s)?';
+ this.deleteModal.message = 'Are you sure you want to delete this menu item?';
this.deleteModal.okButtonText = 'Yes';
this.deleteModal.open();
}
- public newMenuItem() {
- this.menuItemForm = this._fb.group({
- id: this._fb.control(""),
- title: this._fb.control("",Validators.required),
- type: this._fb.control("",Validators.required),
- route: this._fb.control(""),
- url: this._fb.control(""),
- isEnabled: this._fb.control("",Validators.required),
- });
- this.menuItemsModalOpen('Create Menu Item', 'Save Changes');
- }
-
- public editMenuItem() {
- this.menuItemForm = this._fb.group({
- id: this._fb.control("id"),
- title: this._fb.control("HardcodedName",Validators.required),
- type: this._fb.control("internal",Validators.required),
- route: this._fb.control("routeAlex"),
- url: this._fb.control("urlAlex"),
- isEnabled: this._fb.control("enabled",Validators.required),
- });
- this.menuItemsModalOpen('Edit Menu Item', 'Save Changes');
+ public confirmedDeleteMenuItem(data: any, isChild: boolean = false) {
+ this.showLoading = true;
+ this.subscriptions.push(
+ this._helpContentService.deleteMenuItem(this.selectedMenuItem, this.portal).subscribe(
+ _ => {
+ this.deleteMenuItemFromArray(this.selectedMenuItem, this.isChild);
+ UIkit.notification('Menu item have been
successfully deleted', {
+ status: 'success',
+ timeout: 6000,
+ pos: 'bottom-right'
+ });
+ this.showLoading = false;
+ }
+ )
+ )
}
- public deleteMenuItem() {
- console.log('Delete menu item');
- }
-
- public newPageWindow() {
- this.newPageWindowOpen = !this.newPageWindowOpen;
+ private deleteMenuItemFromArray(id: string, isChild: boolean = false) {
+ if(isChild) {
+ let i = this.getActiveRootItem(this.activeRootMenu).items.findIndex(_ => _._id == id);
+ this.getActiveRootItem(this.activeRootMenu).items.splice(i, 1);
+ } else {
+ let i = this.rootMenuItems.findIndex(_ => _._id == id);
+ this.rootMenuItems.splice(i, 1);
+ }
}
private menuItemsModalOpen(title: string, yesBtn: string) {
@@ -217,8 +219,57 @@ export class MenuComponent implements OnInit {
this.editModal.open();
}
- public toggleMenuItems(status: boolean, ids: string[]) {
+ public menuItemSaveConfirmed(data: any) {
+ this.showLoading = true;
+ if(!this.menuItemForm.value._id) {
+ this.subscriptions.push(
+ this._helpContentService.saveMenuItem(