Project

General

Profile

« Previous | Next » 

Revision 60310

[Library | Trunk]: Admin tools pages, fix modals and update behaviour

View differences:

entities.component.ts
1
import {Component, ViewChild, OnInit, ElementRef} from '@angular/core';
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 {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
4
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
5 5
import {CheckEntity, Entity} from '../../utils/entities/adminTool/entity';
6 6
import {Portal} from '../../utils/entities/adminTool/portal';
7 7
import {EnvProperties} from '../../utils/properties/env-properties';
8 8
import {Session} from '../../login/utils/helper.class';
9 9
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
10
import {HelperFunctions} from "../../utils/HelperFunctions.class";
11 10
import {UserManagementService} from '../../services/user-management.service';
12 11
import {Subscriber} from "rxjs";
13 12
import {properties} from "../../../../environments/environment";
14 13
import {ConnectHelper} from "../../connect/connectHelper";
14
import {AlertModal} from "../../utils/modal/alert";
15 15

  
16 16
@Component({
17 17
  selector: 'entities',
......
20 20

  
21 21
export class EntitiesComponent implements OnInit {
22 22
  
23
  @ViewChild('AlertModalSaveEntity') alertModalSaveEntity;
24
  @ViewChild('AlertModalDeleteEntities') alertModalDeleteEntities;
23
  @ViewChild('editModal') editModal: AlertModal;
24
  @ViewChild('deleteModal') deleteModal: AlertModal;
25
  @ViewChild('relatedPages') relatedPages: AlertModal;
25 26
  private selectedEntities: string[] = [];
26 27
  
27 28
  public checkboxes: CheckEntity[] = [];
28 29
  
29 30
  public entities: Entity[] = [];
30 31
  
31
  public myForm: FormGroup;
32
  public entityForm: FormGroup;
32 33
  
33 34
  private searchText: RegExp = new RegExp('');
34 35
  public keyword = '';
......
36 37
  public communities: Portal[] = [];
37 38
  public portal: string;
38 39
  
39
  @ViewChild('AlertModalRelatedPages') alertModalRelatedPages;
40
  
41 40
  public toggleIds: string[];
42 41
  public toggleStatus: boolean;
43 42
  public properties: EnvProperties = properties;
......
49 48
  public isPortalAdministrator = null;
50 49
  public filterForm: FormGroup;
51 50
  private subscriptions: any[] = [];
51
  private index: number;
52 52
  
53 53
  constructor(private element: ElementRef, private route: ActivatedRoute,
54 54
              private _router: Router,
......
61 61
      keyword: [''],
62 62
      status: ['all', Validators.required]
63 63
    });
64
    
65
    this.myForm = this._fb.group({
66
      pid: ['', Validators.required],
67
      name: ['', Validators.required],
68
      isEnabled: '',
69
      _id: ''
70
    });
71 64
    this.subscriptions.push(this.filterForm.get('keyword').valueChanges.subscribe(value => {
72 65
      this.filterBySearch(value);
73 66
    }));
......
149 142
  
150 143
  private deleteEntitiesFromArray(ids: string[]): void {
151 144
    for (let id of ids) {
152
      const i = this.checkboxes.findIndex(_ => _.entity._id === id);
153
      this.checkboxes.splice(i, 1);
145
      let i = this.entities.findIndex(_ => _._id == id);
146
      this.entities.splice(i, 1);
154 147
    }
148
    this.applyFilter();
155 149
  }
156 150
  
157 151
  public confirmDeleteEntity(id: string) {
......
173 167
      this._router.navigate(['/user-info'],
174 168
        {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
175 169
    } else {
176
      this.alertModalDeleteEntities.cancelButton = true;
177
      this.alertModalDeleteEntities.okButton = true;
178
      this.alertModalDeleteEntities.alertTitle = 'Delete Confirmation';
179
      this.alertModalDeleteEntities.message = 'Are you sure you want to delete the selected entity(-ies)?';
180
      this.alertModalDeleteEntities.okButtonText = 'Yes';
181
      this.alertModalDeleteEntities.open();
170
      this.deleteModal.cancelButton = true;
171
      this.deleteModal.okButton = true;
172
      this.deleteModal.alertTitle = 'Delete Confirmation';
173
      this.deleteModal.message = 'Are you sure you want to delete the selected entity(-ies)?';
174
      this.deleteModal.okButtonText = 'Yes';
175
      this.deleteModal.open();
182 176
    }
183 177
  }
184 178
  
......
202 196
  
203 197
  public editEntity(i: number) {
204 198
    const entity: Entity = this.checkboxes[i].entity;
205
    this.myForm = this._fb.group({
206
      name: [entity.name, Validators.required],
207
      _id: entity._id,
208
      pid: [entity.pid, Validators.required],
199
    this.index = this.entities.findIndex(value => value._id === entity._id);
200
    this.entityForm = this._fb.group({
201
      name: this._fb.control(entity.name, Validators.required),
202
      _id: this._fb.control(entity._id),
203
      pid: this._fb.control(entity.pid, Validators.required)
209 204
    });
210 205
    this.modalErrorMessage = '';
211
    this.entitiesModalOpen(this.alertModalSaveEntity, '', 'Save Changes');
206
    this.entitiesModalOpen('Edit Entity', 'Save Changes');
212 207
  }
213 208
  
214 209
  public newEntity() {
215
    this.myForm = this._fb.group({
216
      pid: ['', Validators.required],
217
      name: ['', Validators.required],
218
      isEnabled: '',
219
      _id: ''
210
    this.entityForm = this._fb.group({
211
      _id: this._fb.control(null),
212
      name: this._fb.control('', Validators.required),
213
      pid: this._fb.control('', Validators.required)
220 214
    });
221 215
    this.modalErrorMessage = '';
222
    this.entitiesModalOpen(this.alertModalSaveEntity, '', 'Save');
216
    this.entitiesModalOpen('Create Entity', 'Create');
223 217
  }
224 218
  
225
  private entitiesModalOpen(modal: any, title: string, yesBtn: string) {
219
  private entitiesModalOpen(title: string, yesBtn: string) {
226 220
    if (!Session.isLoggedIn()) {
227 221
      this._router.navigate(['/user-info'],
228 222
        {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
229 223
    } else {
230
      modal.cancelButton = true;
231
      modal.okButton = true;
232
      modal.alertTitle = title;
233
      modal.okButtonText = yesBtn;
234
      modal.open();
224
      this.editModal.cancelButton = true;
225
      this.editModal.okButton = true;
226
      this.editModal.okButtonLeft = false;
227
      this.editModal.alertTitle = title;
228
      this.editModal.okButtonText = yesBtn;
229
      this.editModal.open();
235 230
    }
236 231
  }
237 232
  
......
241 236
        {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
242 237
    } else {
243 238
      this.modalErrorMessage = '';
244
      if (this.myForm.getRawValue()['_id'].length > 0) {
239
      if (this.entityForm.value._id) {
245 240
        this._helpContentService.updateEntity(
246
          <Entity>this.myForm.value, this.properties.adminToolsAPIURL).subscribe(
241
          <Entity>this.entityForm.value, this.properties.adminToolsAPIURL).subscribe(
247 242
          entity => {
248 243
            this.entityUpdatedSuccessfully(entity);
249 244
          },
250 245
          error => this.handleUpdateError('System error updating entity', error)
251 246
        );
252 247
      } else {
253
        this._helpContentService.saveEntity(<Entity>this.myForm.value, this.properties.adminToolsAPIURL).subscribe(
248
        this._helpContentService.saveEntity(<Entity>this.entityForm.value, this.properties.adminToolsAPIURL).subscribe(
254 249
          entity => {
255 250
            this.entitySavedSuccessfully(entity);
256 251
          },
......
262 257
  
263 258
  
264 259
  public entitySavedSuccessfully(entity: Entity) {
265
    this.checkboxes.push(<CheckEntity>{entity: entity, checked: false});
260
    this.entities.push(entity);
261
    this.applyFilter();
266 262
    this.applyCheck(false);
267 263
  }
268 264
  
269 265
  public entityUpdatedSuccessfully(entity: Entity) {
270
    this.checkboxes.find(checkItem => checkItem.entity._id === entity._id).entity = entity;
266
    this.entities[this.index] = entity;
267
    this.applyFilter();
271 268
    this.applyCheck(false);
272 269
  }
273 270
  
......
309 306
  
310 307
  handleUpdateError(message: string, error) {
311 308
    if (error == null) {
312
      this.myForm = this._fb.group({
309
      this.entityForm = this._fb.group({
313 310
        pid: ['', Validators.required],
314 311
        name: ['', Validators.required],
315 312
        isEnabled: '',
......
339 336
      this._router.navigate(['/user-info'],
340 337
        {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}});
341 338
    } else {
342
      this.alertModalRelatedPages.cancelButton = true;
343
      this.alertModalRelatedPages.okButton = true;
344
      this.alertModalRelatedPages.alertTitle = 'Warning';
345
      this.alertModalRelatedPages.message = "This action will affect all search pages related to this entity! Pages' status will change to entity's status! Do you want to continue?";
346
      this.alertModalRelatedPages.okButtonText = 'Yes';
347
      this.alertModalRelatedPages.open();
339
      this.relatedPages.cancelButton = true;
340
      this.relatedPages.okButton = true;
341
      this.relatedPages.alertTitle = 'Warning';
342
      this.relatedPages.message = "This action will affect all search pages related to this entity! Pages' status will change to entity's status! Do you want to continue?";
343
      this.relatedPages.okButtonText = 'Yes';
344
      this.relatedPages.open();
348 345
    }
349 346
  }
350 347
  

Also available in: Unified diff