diff --git a/src/app/stakeholder/stakeholder.component.html b/src/app/stakeholder/stakeholder.component.html index b21d283..131bacd 100644 --- a/src/app/stakeholder/stakeholder.component.html +++ b/src/app/stakeholder/stakeholder.component.html @@ -32,112 +32,31 @@ - - more_horiz - - -
-
-
-
- - close - -
-
- - -
-
- - -
-
-
-
-
-
-
-
-
- -
-
- -
-
-
+
+ more_vert +
+
-
+
  • - + add Create new Topic -
    -
    -
    -
    - - close - -
    -
    - - -
    -
    - - -
    -
    -
    -
    -
    -
    -
    -
    -
    - -
    -
    - -
    -
    -
    -
    -
    -
  • @@ -188,4 +107,23 @@
    - + + You are about to delete "{{stakeholder.topics[index].name}}" topic permanently. + Are you sure you want to proceed? + + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    diff --git a/src/app/stakeholder/stakeholder.component.ts b/src/app/stakeholder/stakeholder.component.ts index 20fe5d8..6c4c0b4 100644 --- a/src/app/stakeholder/stakeholder.component.ts +++ b/src/app/stakeholder/stakeholder.component.ts @@ -12,189 +12,181 @@ import {AlertModal} from "../openaireLibrary/utils/modal/alert"; import {Subscriber} from "rxjs"; import {FormBuilder, FormGroup, Validators} from "@angular/forms"; import {LayoutService} from "../library/sharedComponents/sidebar/layout.service"; -import {IndicatorUtils, StakeholderUtils} from "../utils/indicator-utils"; +import {StakeholderUtils} from "../utils/indicator-utils"; declare var UIkit; @Component({ - selector: 'stakeholder', - templateUrl: './stakeholder.component.html', + selector: 'stakeholder', + templateUrl: './stakeholder.component.html', }) export class StakeholderComponent implements OnInit, OnDestroy { - public subscriptions: any[] = []; - public loading: boolean = true; - public errorCodes: ErrorCodes; - public stakeholder: Stakeholder; - public analysisOpen: boolean = true; - private errorMessages: ErrorMessagesComponent; - public topicFb: FormGroup; - public indicatorUtils: IndicatorUtils = new IndicatorUtils(); - public stakeholderUtils: StakeholderUtils = new StakeholderUtils(); - public element: any; - public index: number; - properties: EnvProperties; - - @ViewChild('deleteTopicModal') deleteTopicModal: AlertModal; - - constructor( - private route: ActivatedRoute, - private router: Router, - private title: Title, - private layoutService: LayoutService, - private fb: FormBuilder, - private stakeholderService: StakeholderService) { - this.errorCodes = new ErrorCodes(); - this.errorMessages = new ErrorMessagesComponent(); - } - - public ngOnInit() { - this.route.data - .subscribe((data: { envSpecific: EnvProperties }) => { - this.properties = data.envSpecific; - this.subscriptions.push(this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => { - if (stakeholder) { - this.stakeholder = HelperFunctions.copy(stakeholder); - this.topicFb = null; - this.title.setTitle(stakeholder.index_name); - } - })); - }); - } - - public ngOnDestroy() { - this.subscriptions.forEach(value => { - if (value instanceof Subscriber) { - value.unsubscribe(); - } - }); - } - - public show(element) { - UIkit.drop(element).show(); - } - - public hide(element) { - UIkit.drop(element).hide(); - } - - get open(): boolean { - return this.layoutService.open; - } - - public toggleOpen(event = null) { - if (!event) { - this.layoutService.setOpen(!this.open); - } else if (event && event['value'] === true) { - this.layoutService.setOpen(false); - } - } - - private buildTopic(topic: Topic) { - let topics = this.stakeholder.topics.filter(element => element._id !== topic._id); - this.topicFb = this.fb.group({ - _id: this.fb.control(topic._id), - name: this.fb.control(topic.name, Validators.required), - description: this.fb.control(topic.description), - alias: this.fb.control(topic.alias, [ - Validators.required, - this.stakeholderUtils.aliasValidator(topics) - ] - ), - isActive: this.fb.control(topic.isActive), - isPublic: this.fb.control(topic.isPublic), - isDefault: this.fb.control(topic.isDefault), - categories: this.fb.control(topic.categories) - }); - this.subscriptions.push(this.topicFb.get('name').valueChanges.subscribe(value => { - let i = 1; - value = this.stakeholderUtils.generateAlias(value); - this.topicFb.controls['alias'].setValue(value); - while (this.topicFb.get('alias').invalid) { - this.topicFb.controls['alias'].setValue(value + i); - i++; + public subscriptions: any[] = []; + public loading: boolean = true; + public errorCodes: ErrorCodes; + public stakeholder: Stakeholder; + public analysisOpen: boolean = true; + private errorMessages: ErrorMessagesComponent; + public form: FormGroup; + public stakeholderUtils: StakeholderUtils = new StakeholderUtils(); + public index: number = -1; + properties: EnvProperties; + + @ViewChild('deleteModal') deleteModal: AlertModal; + @ViewChild('editModal') editModal: AlertModal; + + constructor( + private route: ActivatedRoute, + private router: Router, + private title: Title, + private layoutService: LayoutService, + private fb: FormBuilder, + private stakeholderService: StakeholderService) { + this.errorCodes = new ErrorCodes(); + this.errorMessages = new ErrorMessagesComponent(); + } + + public ngOnInit() { + this.route.data + .subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + this.subscriptions.push(this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => { + if (stakeholder) { + this.stakeholder = HelperFunctions.copy(stakeholder); + this.form = null; + this.title.setTitle(stakeholder.index_name); } })); + }); + } + + public ngOnDestroy() { + this.subscriptions.forEach(value => { + if (value instanceof Subscriber) { + value.unsubscribe(); + } + }); + } + + get open(): boolean { + return this.layoutService.open; + } + + public toggleOpen(event = null) { + if (!event) { + this.layoutService.setOpen(!this.open); + } else if (event && event['value'] === true) { + this.layoutService.setOpen(false); } - - public saveTopicOpen(element, index = -1) { - if (element.className.indexOf('uk-open') !== -1) { - this.hide(element); - } else { - if (index === -1) { - this.buildTopic(new Topic(null, null, null, true, true, false)); - } else { - this.buildTopic(this.stakeholder.topics[index]); - } - this.show(element); - } + } + + private buildTopic(topic: Topic) { + let topics = this.stakeholder.topics.filter(element => element._id !== topic._id); + this.form = this.fb.group({ + _id: this.fb.control(topic._id), + name: this.fb.control(topic.name, Validators.required), + description: this.fb.control(topic.description), + alias: this.fb.control(topic.alias, [ + Validators.required, + this.stakeholderUtils.aliasValidator(topics) + ] + ), + isActive: this.fb.control(topic.isActive), + isPublic: this.fb.control(topic.isPublic), + isDefault: this.fb.control(topic.isDefault), + categories: this.fb.control(topic.categories) + }); + this.subscriptions.push(this.form.get('name').valueChanges.subscribe(value => { + let i = 1; + value = this.stakeholderUtils.generateAlias(value); + this.form.controls['alias'].setValue(value); + while (this.form.get('alias').invalid) { + this.form.controls['alias'].setValue(value + i); + i++; + } + })); + } + + public editTopicOpen(index = -1) { + this.index = index; + if (index === -1) { + this.buildTopic(new Topic(null, null, null, true, true, false)); + } else { + this.buildTopic(this.stakeholder.topics[index]); } - - public saveTopic(element, index = -1) { - if (!this.topicFb.invalid) { - if (index === -1) { - this.save('Topic has been successfully created', element); - } else { - this.save('Topic has been successfully saved', element, index); - } - } + this.editModal.cancelButtonText = 'Cancel'; + this.editModal.okButtonLeft = false; + this.editModal.alertMessage = false; + if (index === -1) { + this.editModal.alertTitle = 'Create a new topic'; + this.editModal.okButtonText = 'Create'; + } else { + this.editModal.alertTitle = 'Edit topic\'s information '; + this.editModal.okButtonText = 'Save'; } - - public deleteTopicOpen(name: string, element, index: number) { - this.element = element; - this.index = index; - this.deleteTopicModal.alertTitle = 'Delete ' + name; - this.deleteTopicModal.cancelButtonText = 'No'; - this.deleteTopicModal.okButtonText = 'Yes'; - this.deleteTopicModal.message = 'This topic will permanently be deleted. Are you sure you want to proceed?'; - this.deleteTopicModal.open(); - } - - private save(message: string, element, index: number = -1) { - let path = [this.stakeholder._id]; - this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.topicFb.value, path).subscribe(topic => { - if (index === -1) { - this.stakeholder.topics.push(topic); - } else { - this.stakeholder.topics[index] = topic; - } - this.stakeholderService.setStakeholder(this.stakeholder); - UIkit.notification(message, { - status: 'success', - timeout: 3000, - pos: 'top-left' - }); - this.hide(element); - }, error => { - UIkit.notification(error.error.message, { - status: 'danger', - timeout: 3000, - pos: 'top-left' - }); - this.hide(element); - }); - } - - deleteTopic() { - let path = [ - this.stakeholder._id, - this.stakeholder.topics[this.index]._id - ]; - this.stakeholderService.deleteElement(this.properties.monitorServiceAPIURL, path).subscribe(() => { - this.stakeholder.topics.splice(this.index, 1); - this.stakeholderService.setStakeholder(this.stakeholder); - UIkit.notification('Topic has been successfully deleted', { - status: 'success', - timeout: 3000, - pos: 'top-left' - }); - this.hide(this.element); - }, error => { - UIkit.notification(error.error.message, { - status: 'danger', - timeout: 3000, - pos: 'top-left' - }); - this.hide(this.element); - }); + this.editModal.open(); + } + + public saveTopic(index = -1) { + if (!this.form.invalid) { + if (index === -1) { + this.save('Topic has been successfully created'); + } else { + this.save('Topic has been successfully saved', index); + } } + } + + public deleteTopicOpen(index: number) { + this.index = index; + this.deleteModal.alertTitle = 'Delete topic'; + this.deleteModal.cancelButtonText = 'No'; + this.deleteModal.okButtonText = 'Yes'; + this.deleteModal.open(); + } + + private save(message: string, index: number = -1) { + let path = [this.stakeholder._id]; + this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.form.value, path).subscribe(topic => { + if (index === -1) { + this.stakeholder.topics.push(topic); + } else { + this.stakeholder.topics[index] = topic; + } + this.stakeholderService.setStakeholder(this.stakeholder); + UIkit.notification(message, { + status: 'success', + timeout: 3000, + pos: 'top-left' + }); + }, error => { + UIkit.notification(error.error.message, { + status: 'danger', + timeout: 3000, + pos: 'top-left' + }); + }); + } + + deleteTopic() { + let path = [ + this.stakeholder._id, + this.stakeholder.topics[this.index]._id + ]; + this.stakeholderService.deleteElement(this.properties.monitorServiceAPIURL, path).subscribe(() => { + this.stakeholder.topics.splice(this.index, 1); + this.stakeholderService.setStakeholder(this.stakeholder); + UIkit.notification('Topic has been successfully deleted', { + status: 'success', + timeout: 3000, + pos: 'top-left' + }); + }, error => { + UIkit.notification(error.error.message, { + status: 'danger', + timeout: 3000, + pos: 'top-left' + }); + }); + } } diff --git a/src/app/topic/indicators.component.html b/src/app/topic/indicators.component.html index 6065f99..44e302f 100644 --- a/src/app/topic/indicators.component.html +++ b/src/app/topic/indicators.component.html @@ -83,7 +83,7 @@
  • {{indicator.isPublic?'Unpublish':'Publish'}}
  • -
  • +
  • Delete
  • @@ -160,7 +160,7 @@
  • {{indicator.isPublic?'Unpublish':'Publish'}}
  • -
  • +
  • Delete
  • @@ -230,7 +230,7 @@ - @@ -318,4 +318,8 @@ - + + You are about to delete + "{{indicator.name?indicator.name:indicator.indicatorPaths[0].parameters.title}}" indicator permanently. + Are you sure you want to proceed? + diff --git a/src/app/topic/indicators.component.ts b/src/app/topic/indicators.component.ts index 5f6dd44..831f9a9 100644 --- a/src/app/topic/indicators.component.ts +++ b/src/app/topic/indicators.component.ts @@ -35,7 +35,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV * Editable indicator */ public indicator: Indicator; - public index: number; + public index: number = -1; /** * Displayed chart and numbers base on Top filters */ @@ -55,8 +55,8 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV public grid: boolean = true; private subscriptions: any[] = []; private urlSubscriptions: any[] = []; - @ViewChild('editIndicatorModal') editIndicatorModal: AlertModal; - @ViewChild('deleteIndicatorModal') deleteIndicatorModal: AlertModal; + @ViewChild('editModal') editModal: AlertModal; + @ViewChild('deleteModal') deleteModal: AlertModal; constructor(private layoutService: LayoutService, private stakeholderService: StakeholderService, @@ -320,6 +320,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV } }); this.index = (id) ? this.charts.findIndex(value => value._id === id) : -1; + console.log(this.index); if (this.index !== -1) { this.indicator = HelperFunctions.copy(this.charts[this.index]); this.indicatorFb = this.fb.group({ @@ -348,16 +349,17 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV }); this.addIndicatorPath(); } - this.editIndicatorModal.cancelButtonText = 'Cancel'; - this.editIndicatorModal.okButtonLeft = false; - this.editIndicatorModal.alertMessage = false; + this.editModal.cancelButtonText = 'Cancel'; + this.editModal.okButtonLeft = false; + this.editModal.alertMessage = false; if (this.index === -1) { - this.editIndicatorModal.alertTitle = 'Create a new chart Indicator'; - this.editIndicatorModal.okButtonText = 'Save'; + this.editModal.alertTitle = 'Create a new chart indicator'; + this.editModal.okButtonText = 'Save'; } else { - this.editIndicatorModal.okButtonText = 'Save Changes'; + this.editModal.alertTitle = 'Edit chart indicator\'s information'; + this.editModal.okButtonText = 'Save Changes'; } - this.editIndicatorModal.open(); + this.editModal.open(); } saveIndicator() { @@ -428,11 +430,10 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV } else { this.indicator = this.numbers.find(value => value._id == id); } - this.deleteIndicatorModal.alertTitle = 'Delete ' + this.indicator.name; - this.deleteIndicatorModal.cancelButtonText = 'No'; - this.deleteIndicatorModal.okButtonText = 'Yes'; - this.deleteIndicatorModal.message = 'This indicator will permanently be deleted. Are you sure you want to proceed?'; - this.deleteIndicatorModal.open(); + this.deleteModal.alertTitle = 'Delete indicator'; + this.deleteModal.cancelButtonText = 'No'; + this.deleteModal.okButtonText = 'Yes'; + this.deleteModal.open(); } deleteIndicator() { diff --git a/src/app/topic/topic.component.html b/src/app/topic/topic.component.html index 231066c..d49cd49 100644 --- a/src/app/topic/topic.component.html +++ b/src/app/topic/topic.component.html @@ -14,294 +14,101 @@ - - more_horiz - - -
    -
    -
    -
    - - close - -
    -
    - - -
    -
    - - -
    -
    -
    -
    -
    -
    -
    -
    -
    - -
    -
    - -
    -
    -
    +
    + more_vert +
    +
    -
    +
  • - + add Create new Category -
    -
    -
    -
    - - close - -
    -
    - - -
    -
    - - -
    -
    -
    -
    -
    -
    -
    -
    -
    - -
    -
    - -
    -
    -
    -
    -
    -
  • @@ -311,7 +118,24 @@ [topicIndex]="topicIndex" [categoryIndex]="categoryIndex" [subcategoryIndex]="subCategoryIndex"> - - - + + You are about to delete "{{element.name}}" {{type}} permanently. + Are you sure you want to proceed? + + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    diff --git a/src/app/topic/topic.component.ts b/src/app/topic/topic.component.ts index b571abb..35af0f8 100644 --- a/src/app/topic/topic.component.ts +++ b/src/app/topic/topic.component.ts @@ -8,7 +8,7 @@ import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class"; import {AlertModal} from "../openaireLibrary/utils/modal/alert"; import {Subscriber, Subscription} from "rxjs"; import {FormBuilder, FormGroup, Validators} from "@angular/forms"; -import {IndicatorUtils, StakeholderUtils} from "../utils/indicator-utils"; +import {StakeholderUtils} from "../utils/indicator-utils"; declare var UIkit; @@ -19,7 +19,6 @@ declare var UIkit; export class TopicComponent implements OnInit, OnDestroy { public subscriptions: any[] = []; public properties: EnvProperties; - public indicatorUtils: IndicatorUtils = new IndicatorUtils(); public stakeholderUtils: StakeholderUtils = new StakeholderUtils(); public loading: boolean = true; public stakeholder: Stakeholder; @@ -27,32 +26,29 @@ export class TopicComponent implements OnInit, OnDestroy { * Current topic **/ public topicIndex: number = 0; - public topicFb: FormGroup; - /** * categoryIndex: Current category to be edited, selectedCategoryIndex: selected on menu(opened) */ public categoryIndex: number = 0; public selectedCategoryIndex: number = 0; - public categoryFb: FormGroup; /** * Current Subcategory to be edited */ public subCategoryIndex: number = 0; - public subcategoryFb: FormGroup; /** - * Current drop element and index of topic, category or subcategory to be deleted. + * Current element and index of topic, category or subcategory to be deleted. */ - public element: any; - public index: number; + public form: FormGroup; + public element: Topic | Category | SubCategory; + public type: 'topic' | 'category' | 'subcategory' = "topic"; + public index: number = -1; /** * Check form validity */ public toggle: boolean = false; - @ViewChild('deleteTopicModal') deleteTopicModal: AlertModal; - @ViewChild('deleteCategoryModal') deleteCategoryModal: AlertModal; - @ViewChild('deleteSubcategoryModal') deleteSubcategoryModal: AlertModal; + @ViewChild('deleteModal') deleteModal: AlertModal; + @ViewChild('editModal') editModal: AlertModal; constructor( private route: ActivatedRoute, @@ -95,18 +91,30 @@ export class TopicComponent implements OnInit, OnDestroy { } }); } - - public hide(element) { - UIkit.drop(element).hide(); + + public saveElement() { + if(this.type === "topic") { + this.saveTopic(); + } else if(this.type === "category") { + this.saveCategory(); + } else { + this.saveSubCategory(); + } } - - public show(element) { - UIkit.drop(element).show(); + + public deleteElement() { + if(this.type === "topic") { + this.deleteTopic(); + } else if(this.type === "category") { + this.deleteCategory(); + } else { + this.deleteSubcategory(); + } } - + private buildTopic(topic: Topic) { let topics = this.stakeholder.topics.filter(element => element._id !== topic._id); - this.topicFb = this.fb.group({ + this.form = this.fb.group({ _id: this.fb.control(topic._id), name: this.fb.control(topic.name, Validators.required), description: this.fb.control(topic.description), @@ -120,48 +128,49 @@ export class TopicComponent implements OnInit, OnDestroy { isDefault: this.fb.control(topic.isDefault), categories: this.fb.control(topic.categories) }); - this.subscriptions.push(this.topicFb.get('name').valueChanges.subscribe(value => { + this.subscriptions.push(this.form.get('name').valueChanges.subscribe(value => { let i = 1; value = this.stakeholderUtils.generateAlias(value); - this.topicFb.controls['alias'].setValue(value); - while (this.topicFb.get('alias').invalid) { - this.topicFb.controls['alias'].setValue(value + i); + this.form.controls['alias'].setValue(value); + while (this.form.get('alias').invalid) { + this.form.controls['alias'].setValue(value + i); i++; } })); } - public editTopicOpen(element) { - if (element.className.indexOf('uk-open') !== -1) { - this.hide(element); - } else { - this.buildTopic(this.stakeholder.topics[this.topicIndex]); - this.show(element); - } + public editTopicOpen() { + this.index = this.topicIndex; + this.type = 'topic'; + this.buildTopic(this.stakeholder.topics[this.index]); + this.editOpen(); } - public saveTopic(element) { - if (!this.topicFb.invalid) { + public saveTopic() { + if (!this.form.invalid) { let path = [this.stakeholder._id]; let callback = (topic: Topic): void => { - this.stakeholder.topics[this.topicIndex] = topic; + this.stakeholder.topics[this.index] = topic; this.stakeholderService.setStakeholder(this.stakeholder); }; - this.save('Topic has been successfully saved', element, path, this.topicFb.value, callback, true); + this.save('Topic has been successfully saved', path, this.form.value, callback, true); } } - public deleteTopicOpen(name: string, element) { - this.deleteOpen(name, 'topic', this.deleteTopicModal, element, this.topicIndex); + public deleteTopicOpen() { + this.type = 'topic'; + this.index = this.topicIndex; + this.element = this.stakeholder.topics[this.index]; + this.deleteOpen(); } public deleteTopic() { let path: string[] = [ this.stakeholder._id, - this.stakeholder.topics[this.topicIndex]._id + this.stakeholder.topics[this.index]._id ]; let callback = (): void => { - this.stakeholder.topics.splice(this.topicIndex, 1); + this.stakeholder.topics.splice(this.index, 1); this.stakeholderService.setStakeholder(this.stakeholder); }; this.delete('Topic has been successfully be deleted', path, callback, true); @@ -178,7 +187,7 @@ export class TopicComponent implements OnInit, OnDestroy { private buildCategory(category: Category) { let categories = this.stakeholder.topics[this.topicIndex].categories.filter(element => element._id !== category._id); - this.categoryFb = this.fb.group({ + this.form = this.fb.group({ _id: this.fb.control(category._id), name: this.fb.control(category.name, Validators.required), description: this.fb.control(category.description), @@ -192,51 +201,52 @@ export class TopicComponent implements OnInit, OnDestroy { isDefault: this.fb.control(category.isDefault), subCategories: this.fb.control(category.subCategories) }); - this.subscriptions.push(this.categoryFb.get('name').valueChanges.subscribe(value => { + this.subscriptions.push(this.form.get('name').valueChanges.subscribe(value => { let i = 1; value = this.stakeholderUtils.generateAlias(value); - this.categoryFb.controls['alias'].setValue(value); - while (this.categoryFb.get('alias').invalid) { - this.categoryFb.controls['alias'].setValue(value + i); + this.form.controls['alias'].setValue(value); + while (this.form.get('alias').invalid) { + this.form.controls['alias'].setValue(value + i); i++; } })); } - public editCategoryOpen(element, index: number = -1) { - if (element.className.indexOf('uk-open') !== -1) { - this.hide(element); + public editCategoryOpen(index: number = -1) { + this.index = index; + this.type = 'category'; + if (index === -1) { + this.buildCategory(new Category(null, null, null, true, true)); } else { - if (index === -1) { - this.buildCategory(new Category(null, null, null, true, true)); - } else { - this.buildCategory(this.stakeholder.topics[this.topicIndex].categories[index]); - } - this.show(element); + this.buildCategory(this.stakeholder.topics[this.topicIndex].categories[index]); } + this.editOpen(); } - public saveCategory(element, index = -1) { - if (!this.categoryFb.invalid) { + public saveCategory() { + if (!this.form.invalid) { let path = [this.stakeholder._id, this.stakeholder.topics[this.topicIndex]._id]; let callback = (category: Category): void => { - if (index === -1) { + if (this.index === -1) { this.stakeholder.topics[this.topicIndex].categories.push(category); } else { - this.stakeholder.topics[this.topicIndex].categories[index] = HelperFunctions.copy(category); + this.stakeholder.topics[this.topicIndex].categories[this.index] = HelperFunctions.copy(category); } this.stakeholderService.setStakeholder(this.stakeholder); }; - if (index === -1) { - this.save('Category has been successfully created', element, path, this.categoryFb.value, callback); + if (this.index === -1) { + this.save('Category has been successfully created', path, this.form.value, callback); } else { - this.save('Category has been successfully saved', element, path, this.categoryFb.value, callback); + this.save('Category has been successfully saved', path, this.form.value, callback); } } } - public deleteCategoryOpen(name: string, element, index) { - this.deleteOpen(name, 'category', this.deleteCategoryModal, element, index); + public deleteCategoryOpen(index: number) { + this.type = 'category'; + this.index = index; + this.element = this.stakeholder.topics[this.topicIndex].categories[this.index]; + this.deleteOpen(); } public deleteCategory() { @@ -254,7 +264,7 @@ export class TopicComponent implements OnInit, OnDestroy { private buildSubcategory(subCategory: SubCategory) { let subCategories = this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories.filter(element => element._id !== subCategory._id); - this.subcategoryFb = this.fb.group({ + this.form = this.fb.group({ _id: this.fb.control(subCategory._id), name: this.fb.control(subCategory.name, Validators.required), description: this.fb.control(subCategory.description), @@ -269,56 +279,56 @@ export class TopicComponent implements OnInit, OnDestroy { charts: this.fb.control(subCategory.charts), numbers: this.fb.control(subCategory.numbers) }); - this.subscriptions.push(this.subcategoryFb.get('name').valueChanges.subscribe(value => { + this.subscriptions.push(this.form.get('name').valueChanges.subscribe(value => { let i = 1; value = this.stakeholderUtils.generateAlias(value); - this.subcategoryFb.controls['alias'].setValue(value); - while (this.subcategoryFb.get('alias').invalid) { - this.subcategoryFb.controls['alias'].setValue(value + i); + this.form.controls['alias'].setValue(value); + while (this.form.get('alias').invalid) { + this.form.controls['alias'].setValue(value + i); i++; } })); } - public editSubCategoryOpen(element, index: number = -1) { - if (element.className.indexOf('uk-open') !== -1) { - this.hide(element); + public editSubCategoryOpen(index: number = -1) { + this.index = index; + this.type = 'subcategory'; + if (index === -1) { + this.buildSubcategory(new SubCategory(null, null, null, true, true)); } else { - if (index === -1) { - this.buildSubcategory(new SubCategory(null, null, null, true, true)); - } else { - this.buildSubcategory(this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories[index]); - } - this.show(element); + this.buildSubcategory(this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories[index]); } + this.editOpen(); } - public saveSubCategory(element, index = -1) { - if (!this.subcategoryFb.invalid) { + public saveSubCategory() { + if (!this.form.invalid) { let path: string[] = [ this.stakeholder._id, this.stakeholder.topics[this.topicIndex]._id, this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex]._id, ]; let callback = (subCategory: SubCategory): void => { - if (index === -1) { + if (this.index === -1) { this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories.push(subCategory); } else { - this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories[index] = subCategory; + this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories[this.index] = subCategory; } this.stakeholderService.setStakeholder(this.stakeholder); }; - if (index === -1) { - this.save('Subcategory has been successfully created', element, path, this.subcategoryFb.value, callback); + if (this.index === -1) { + this.save('Subcategory has been successfully created', path, this.form.value, callback); } else { - this.save('Subcategory has been successfully saved', element, path, this.subcategoryFb.value, callback); + this.save('Subcategory has been successfully saved', path, this.form.value, callback); } - this.hide(element); } } - public deleteSubcategoryOpen(name: string, element, index) { - this.deleteOpen(name, 'subcategory', this.deleteSubcategoryModal, element, index); + public deleteSubcategoryOpen(index) { + this.type = 'subcategory'; + this.index = index; + this.element = this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories[this.index]; + this.deleteOpen(); } public deleteSubcategory() { @@ -338,18 +348,29 @@ export class TopicComponent implements OnInit, OnDestroy { private navigateToError() { this.router.navigate(['/error'], {queryParams: {'page': this.router.url}}); } - - private deleteOpen(name: string, type: string, modal: AlertModal, element, index) { - this.element = element; - this.index = index; - modal.alertTitle = 'Delete ' + name; - modal.cancelButtonText = 'No'; - modal.okButtonText = 'Yes'; - modal.message = 'This ' + type + ' will permanently be deleted. Are you sure you want to proceed?'; - modal.open(); + + private editOpen() { + this.editModal.cancelButtonText = 'Cancel'; + this.editModal.okButtonLeft = false; + this.editModal.alertMessage = false; + if (this.index === -1) { + this.editModal.alertTitle = 'Create a new ' + this.type; + this.editModal.okButtonText = 'Create'; + } else { + this.editModal.alertTitle = 'Edit ' + this.type + '\'s information '; + this.editModal.okButtonText = 'Save'; + } + this.editModal.open(); } - private save(message: string, element, path: string[], saveElement: any, callback: Function, redirect = false) { + private deleteOpen() { + this.deleteModal.alertTitle = 'Delete ' + this.type; + this.deleteModal.cancelButtonText = 'No'; + this.deleteModal.okButtonText = 'Yes'; + this.deleteModal.open(); + } + + private save(message: string, path: string[], saveElement: any, callback: Function, redirect = false) { this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, saveElement, path).subscribe(saveElement => { callback(saveElement); UIkit.notification(message, { @@ -362,14 +383,12 @@ export class TopicComponent implements OnInit, OnDestroy { relativeTo: this.route }); } - this.hide(element); }, error => { UIkit.notification(error.error.message, { status: 'danger', timeout: 3000, pos: 'top-left' }); - this.hide(element); }); } @@ -384,14 +403,12 @@ export class TopicComponent implements OnInit, OnDestroy { if (redirect) { this.back(); } - this.hide(this.element); }, error => { UIkit.notification(error.error.message, { status: 'danger', timeout: 3000, pos: 'top-left' }); - this.hide(this.element); }); } diff --git a/src/assets/theme-assets/dashboard-custom.css b/src/assets/theme-assets/dashboard-custom.css index a68b69a..dc54746 100644 --- a/src/assets/theme-assets/dashboard-custom.css +++ b/src/assets/theme-assets/dashboard-custom.css @@ -20,7 +20,8 @@ html .dashboard { display: none; } -.dashboard li > a:hover .onHover { +.dashboard li > a:hover .onHover, +.dashboard li > a .onHover.uk-open { display: block; } @@ -46,23 +47,49 @@ html .dashboard { .dashboard #sidebar_main .menu_section > ul > li > a { font-weight: 700; + overflow: unset; +} + +.dashboard #sidebar_main .menu_section > ul > li:not([class*=md-bg-]) > a:hover { + background-color: #F0F0F0; } .dashboard #sidebar_main .menu_section > ul > li > a > .menu_icon { width: 30px; } +.dashboard #sidebar_main .menu_section > ul > li > ul > li > a:hover { + background-color: #F0F0F0; + margin-right: 5px; +} + .dashboard #sidebar_main .menu_section > ul li > a { font-size: var(--sidebar-font-size); color: rgba(0, 0, 0, 0.7); } +.dashboard #sidebar_main .menu_section .uk-dropdown { + min-width: 150px; +} + +.dashboard #sidebar_main .menu_section .uk-dropdown > ul { + display: block; + margin: 0; + text-align: start; +} + +.dashboard #sidebar_main .menu_section .uk-dropdown > ul > li > a { + padding: 5px 10px; + color: black !important; +} + .dashboard #sidebar_main .menu_section > ul ul > li > a { line-height: 20px; } .dashboard #sidebar_main .menu_section > ul li > a { display: flex; + align-items: center; } body.dashboard {