Revision 57959
Added by Konstantinos Triantafyllou over 4 years ago
topic.component.ts | ||
---|---|---|
10 | 10 |
import {FormBuilder, FormGroup, Validators} from "@angular/forms"; |
11 | 11 |
import {StakeholderUtils} from "../utils/indicator-utils"; |
12 | 12 |
import {StringUtils} from "../openaireLibrary/utils/string-utils.class"; |
13 |
import {IDeactivateComponent} from "../openaireLibrary/utils/can-exit.guard"; |
|
13 | 14 |
|
14 | 15 |
declare var UIkit; |
15 | 16 |
|
... | ... | |
17 | 18 |
selector: 'topic', |
18 | 19 |
templateUrl: './topic.component.html', |
19 | 20 |
}) |
20 |
export class TopicComponent implements OnInit, OnDestroy { |
|
21 |
export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
|
|
21 | 22 |
public subscriptions: any[] = []; |
22 | 23 |
public properties: EnvProperties; |
23 | 24 |
public stakeholderUtils: StakeholderUtils = new StakeholderUtils(); |
... | ... | |
70 | 71 |
} |
71 | 72 |
subscription = this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => { |
72 | 73 |
if (stakeholder) { |
73 |
this.stakeholder = HelperFunctions.copy(stakeholder);
|
|
74 |
this.stakeholder = stakeholder;
|
|
74 | 75 |
this.topicIndex = this.stakeholder.topics.findIndex(topic => topic.alias === params['topic']); |
75 | 76 |
if (this.topicIndex === -1) { |
76 | 77 |
this.navigateToError(); |
... | ... | |
86 | 87 |
} |
87 | 88 |
|
88 | 89 |
public ngOnDestroy() { |
90 |
} |
|
91 |
|
|
92 |
canExit():boolean { |
|
89 | 93 |
this.subscriptions.forEach(value => { |
90 | 94 |
if (value instanceof Subscriber) { |
91 | 95 |
value.unsubscribe(); |
92 | 96 |
} |
93 | 97 |
}); |
98 |
this.stakeholderService.setStakeholder(this.stakeholder); |
|
99 |
return true; |
|
94 | 100 |
} |
95 | 101 |
|
96 | 102 |
public saveElement() { |
... | ... | |
126 | 132 |
), |
127 | 133 |
isActive: this.fb.control(topic.isActive), |
128 | 134 |
isPublic: this.fb.control(topic.isPublic), |
129 |
isDefault: this.fb.control(topic.isDefault),
|
|
135 |
defaultId: this.fb.control(topic.defaultId),
|
|
130 | 136 |
categories: this.fb.control(topic.categories) |
131 | 137 |
}); |
132 | 138 |
this.subscriptions.push(this.form.get('name').valueChanges.subscribe(value => { |
... | ... | |
152 | 158 |
let path = [this.stakeholder._id]; |
153 | 159 |
let callback = (topic: Topic): void => { |
154 | 160 |
this.stakeholder.topics[this.index] = topic; |
155 |
this.stakeholderService.setStakeholder(this.stakeholder); |
|
156 | 161 |
}; |
157 | 162 |
this.save('Topic has been successfully saved', path, this.form.value, callback, true); |
158 | 163 |
} |
... | ... | |
192 | 197 |
]; |
193 | 198 |
let callback = (): void => { |
194 | 199 |
this.stakeholder.topics.splice(this.index, 1); |
195 |
this.stakeholderService.setStakeholder(this.stakeholder); |
|
196 | 200 |
}; |
197 | 201 |
this.delete('Topic has been successfully be deleted', path, callback, true); |
198 | 202 |
} |
... | ... | |
219 | 223 |
), |
220 | 224 |
isActive: this.fb.control(category.isActive), |
221 | 225 |
isPublic: this.fb.control(category.isPublic), |
222 |
isDefault: this.fb.control(category.isDefault),
|
|
226 |
defaultId: this.fb.control(category.defaultId),
|
|
223 | 227 |
subCategories: this.fb.control(category.subCategories) |
224 | 228 |
}); |
225 | 229 |
this.subscriptions.push(this.form.get('name').valueChanges.subscribe(value => { |
... | ... | |
253 | 257 |
} else { |
254 | 258 |
this.stakeholder.topics[this.topicIndex].categories[this.index] = HelperFunctions.copy(category); |
255 | 259 |
} |
256 |
this.stakeholderService.setStakeholder(this.stakeholder); |
|
257 | 260 |
}; |
258 | 261 |
if (this.index === -1) { |
259 | 262 |
this.save('Category has been successfully created', path, this.form.value, callback); |
... | ... | |
300 | 303 |
]; |
301 | 304 |
let callback = (): void => { |
302 | 305 |
this.stakeholder.topics[this.topicIndex].categories.splice(this.index, 1); |
303 |
this.stakeholderService.setStakeholder(this.stakeholder); |
|
304 | 306 |
}; |
305 | 307 |
this.delete('Category has been successfully be deleted', path, callback); |
306 | 308 |
} |
... | ... | |
318 | 320 |
), |
319 | 321 |
isActive: this.fb.control(subCategory.isActive), |
320 | 322 |
isPublic: this.fb.control(subCategory.isPublic), |
321 |
isDefault: this.fb.control(subCategory.isDefault),
|
|
323 |
defaultId: this.fb.control(subCategory.defaultId),
|
|
322 | 324 |
charts: this.fb.control(subCategory.charts), |
323 | 325 |
numbers: this.fb.control(subCategory.numbers) |
324 | 326 |
}); |
... | ... | |
357 | 359 |
} else { |
358 | 360 |
this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories[this.index] = subCategory; |
359 | 361 |
} |
360 |
this.stakeholderService.setStakeholder(this.stakeholder); |
|
361 | 362 |
}; |
362 | 363 |
if (this.index === -1) { |
363 | 364 |
this.save('Subcategory has been successfully created', path, this.form.value, callback); |
... | ... | |
407 | 408 |
]; |
408 | 409 |
let callback = (): void => { |
409 | 410 |
this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories.splice(this.index, 1); |
410 |
this.stakeholderService.setStakeholder(this.stakeholder); |
|
411 | 411 |
}; |
412 | 412 |
this.delete('Subcategory has been successfully be deleted', path, callback); |
413 | 413 |
} |
... | ... | |
482 | 482 |
private toggleStatus(element: Topic | Category | SubCategory, path: string[]) { |
483 | 483 |
this.stakeholderService.toggleStatus(this.properties.monitorServiceAPIURL, path).subscribe(isActive => { |
484 | 484 |
element.isActive = isActive; |
485 |
this.stakeholderService.setStakeholder(this.stakeholder); |
|
486 | 485 |
UIkit.notification(StringUtils.capitalize(this.type) + ' has been successfully ' + (isActive ? 'activated' : 'deactivated'), { |
487 | 486 |
status: 'success', |
488 | 487 |
timeout: 3000, |
... | ... | |
500 | 499 |
private toggleAccess(element: Topic | Category | SubCategory, path: string[]) { |
501 | 500 |
this.stakeholderService.toggleAccess(this.properties.monitorServiceAPIURL, path).subscribe(isPublic => { |
502 | 501 |
element.isPublic = isPublic; |
503 |
this.stakeholderService.setStakeholder(this.stakeholder); |
|
504 | 502 |
UIkit.notification(StringUtils.capitalize(this.type) + ' has been successfully changed to ' + (isPublic ? 'public' : 'private'), { |
505 | 503 |
status: 'success', |
506 | 504 |
timeout: 3000, |
Also available in: Unified diff
[Monitor Dashboard | Trunk]: Change default -> dedaultId. Add section on stakeholder model. Change reorderto be suitable for sections. Create types for stakeholder fixed values.