Revision 60331
Added by Konstantinos Triantafyllou about 3 years ago
pages.component.ts | ||
---|---|---|
1 | 1 |
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core'; |
2 | 2 |
import {ActivatedRoute, Router} from '@angular/router'; |
3 | 3 |
import {HelpContentService} from '../../services/help-content.service'; |
4 |
import {FormArray, FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
|
|
4 |
import {FormArray, FormBuilder, FormGroup, Validators} from '@angular/forms'; |
|
5 | 5 |
import {CheckPage, Page} from '../../utils/entities/adminTool/page'; |
6 |
import {Portal} from '../../utils/entities/adminTool/portal'; |
|
7 |
import {CheckEntity, Entity} from '../../utils/entities/adminTool/entity'; |
|
6 |
import {Entity} from '../../utils/entities/adminTool/entity'; |
|
8 | 7 |
import {EnvProperties} from '../../utils/properties/env-properties'; |
9 | 8 |
import {Session} from '../../login/utils/helper.class'; |
10 | 9 |
import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; |
11 |
import {HelperFunctions} from '../../utils/HelperFunctions.class'; |
|
12 | 10 |
import {UserManagementService} from '../../services/user-management.service'; |
13 |
import {Observable, Subscriber} from "rxjs"; |
|
14 |
import {map, startWith} from "rxjs/operators"; |
|
15 |
import {MatAutocompleteSelectedEvent} from "@angular/material"; |
|
11 |
import {Subscriber} from "rxjs"; |
|
16 | 12 |
import {PortalUtils} from "../portal/portalHelper"; |
17 | 13 |
import {properties} from "../../../../environments/environment"; |
18 | 14 |
import {ConnectHelper} from "../../connect/connectHelper"; |
19 | 15 |
import {Option} from "../../sharedComponents/input/input.component"; |
20 | 16 |
import {AlertModal} from "../../utils/modal/alert"; |
21 | 17 |
|
18 |
declare var UIkit; |
|
19 |
|
|
22 | 20 |
@Component({ |
23 | 21 |
selector: 'pages', |
24 | 22 |
templateUrl: './pages.component.html', |
25 | 23 |
}) |
26 |
|
|
27 | 24 |
export class PagesComponent implements OnInit { |
28 | 25 |
|
29 | 26 |
@ViewChild('editModal') editModal: AlertModal; |
... | ... | |
100 | 97 |
this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.portal; |
101 | 98 |
})); |
102 | 99 |
})); |
103 |
|
|
104 | 100 |
this.subscriptions.push(this._helpContentService.getEntities(this.properties.adminToolsAPIURL).subscribe( |
105 | 101 |
entities => { |
106 | 102 |
this.allEntities = []; |
... | ... | |
110 | 106 |
value: entity |
111 | 107 |
}); |
112 | 108 |
}); |
113 |
this.showLoading = false; |
|
114 | 109 |
}, |
115 | 110 |
error => this.handleError('System error retrieving pages', error))); |
116 | 111 |
|
... | ... | |
139 | 134 |
this.showLoading = true; |
140 | 135 |
this.updateErrorMessage = ''; |
141 | 136 |
this.errorMessage = ''; |
142 |
|
|
143 | 137 |
this.pageWithDivIds = []; |
144 |
|
|
145 | 138 |
let parameters = ''; |
146 | 139 |
if (this.pagesType) { |
147 | 140 |
parameters = '?page_type=' + this.pagesType; |
... | ... | |
279 | 272 |
this.subscriptions.push(this._helpContentService.deletePages(this.selectedPages, this.properties.adminToolsAPIURL).subscribe( |
280 | 273 |
_ => { |
281 | 274 |
this.deletePagesFromArray(this.selectedPages); |
275 |
UIkit.notification('Pages have been <b>successfully deleted</b>', { |
|
276 |
status: 'success', |
|
277 |
timeout: 6000, |
|
278 |
pos: 'bottom-right' |
|
279 |
}); |
|
282 | 280 |
this.showLoading = false; |
283 | 281 |
}, |
284 | 282 |
error => this.handleUpdateError('System error deleting the selected pages', error) |
... | ... | |
352 | 350 |
} |
353 | 351 |
|
354 | 352 |
public pageSaveConfirmed(data: any) { |
353 |
this.showLoading = true; |
|
355 | 354 |
if (!Session.isLoggedIn()) { |
356 | 355 |
this._router.navigate(['/user-info'], { |
357 | 356 |
queryParams: { |
... | ... | |
365 | 364 |
this.subscriptions.push(this._helpContentService.savePage(<Page>this.pageForm.value, this.properties.adminToolsAPIURL).subscribe( |
366 | 365 |
page => { |
367 | 366 |
this.pageSavedSuccessfully(page, true); |
367 |
UIkit.notification('Page <b>' + page.name + '</b> has been <b>successfully created</b>', { |
|
368 |
status: 'success', |
|
369 |
timeout: 6000, |
|
370 |
pos: 'bottom-right' |
|
371 |
}); |
|
368 | 372 |
}, |
369 | 373 |
error => this.handleUpdateError('System error creating page', error) |
370 | 374 |
)); |
... | ... | |
373 | 377 |
this.subscriptions.push(this._helpContentService.updatePage(<Page>this.pageForm.value, this.properties.adminToolsAPIURL).subscribe( |
374 | 378 |
page => { |
375 | 379 |
this.pageSavedSuccessfully(page, false); |
380 |
UIkit.notification('Page <b>' + page.name + '</b> has been <b>successfully updated</b>', { |
|
381 |
status: 'success', |
|
382 |
timeout: 6000, |
|
383 |
pos: 'bottom-right' |
|
384 |
}); |
|
376 | 385 |
}, |
377 | 386 |
error => this.handleUpdateError('System error updating page', error) |
378 | 387 |
)); |
... | ... | |
389 | 398 |
} |
390 | 399 |
this.applyFilters(); |
391 | 400 |
this.applyCheck(false); |
401 |
this.showLoading = false; |
|
392 | 402 |
} |
393 | 403 |
|
394 | 404 |
public applyFilters() { |
... | ... | |
440 | 450 |
this.updateErrorMessage = message;// + ' (Server responded: ' + error + ')'; |
441 | 451 |
console.log('Server responded: ' + error); |
442 | 452 |
} |
443 |
|
|
453 |
UIkit.notification('An error has occurred. Please try again later', { |
|
454 |
status: 'danger', |
|
455 |
timeout: 6000, |
|
456 |
pos: 'bottom-right' |
|
457 |
}); |
|
444 | 458 |
this.showLoading = false; |
445 | 459 |
} |
446 | 460 |
|
461 |
public getEntitiesAsString(page: Page): string { |
|
462 |
if(page.entities) { |
|
463 |
return (<any[]> page.entities).map((page: Entity) => page.name).join(','); |
|
464 |
} |
|
465 |
return ''; |
|
466 |
} |
|
467 |
|
|
447 | 468 |
// public filterByPortal(event: any) { |
448 | 469 |
// this.portal = event.target.value; |
449 | 470 |
// this.applyPortalFilter(this.portal); |
Also available in: Unified diff
[Library | Trunk]: Admin tools pages add loading and notifications