Project

General

Profile

« Previous | Next » 

Revision 57706

[Monitor Dashboard]: Merge create and edit modals. Rename SidebarService to LayoutService and add hasSidebar on it

View differences:

indicators.component.ts
1 1
import {AfterViewInit, Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild} from "@angular/core";
2
import {SideBarService} from "../library/sharedComponents/sidebar/sideBar.service";
3 2
import {Indicator, IndicatorPath, Stakeholder} from "../utils/entities/stakeholder";
4 3
import {IndicatorUtils, Option} from "../utils/indicator-utils";
5 4
import {FormArray, FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms";
......
10 9
import {StakeholderService} from "../services/stakeholder.service";
11 10
import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties";
12 11
import {Subscriber} from "rxjs";
12
import {LayoutService} from "../library/sharedComponents/sidebar/layout.service";
13 13

  
14 14
declare var UIkit;
15 15

  
......
31 31
  public stakeholder: Stakeholder = null;
32 32
  public indicatorUtils: IndicatorUtils = new IndicatorUtils();
33 33
  public indicatorFb: FormGroup;
34
  public editIndicatorFb: FormGroup;
35 34
  /**
36 35
   * Editable indicator
37 36
   */
......
55 54
   */
56 55
  public grid: boolean = true;
57 56
  private subscriptions: any[] = [];
58

  
59
  @ViewChild('createIndicatorModal') createIndicatorModal: AlertModal;
60 57
  @ViewChild('editIndicatorModal') editIndicatorModal: AlertModal;
61 58
  @ViewChild('deleteIndicatorModal') deleteIndicatorModal: AlertModal;
62 59

  
63
  constructor(private sideBarService: SideBarService,
60
  constructor(private layoutService: LayoutService,
64 61
              private stakeholderService: StakeholderService,
65 62
              private statisticsService: StatisticsService,
66 63
              private fb: FormBuilder,
......
108 105

  
109 106
  public toggleOpen(event = null) {
110 107
    if (!event) {
111
      this.sideBarService.setOpen(!this.open);
108
      this.layoutService.setOpen(!this.open);
112 109
    } else if (event && event['value'] === true) {
113
      this.sideBarService.setOpen(false);
110
      this.layoutService.setOpen(false);
114 111
    }
115 112
  }
116 113

  
......
226 223
  }
227 224

  
228 225
  get open(): boolean {
229
    return this.sideBarService.open;
226
    return this.layoutService.open;
230 227
  }
231 228

  
232 229
  get canNumbersReorder(): boolean {
......
249 246
  }
250 247

  
251 248
  public get indicatorPaths(): FormArray {
252
    return this.editIndicatorFb.get('indicatorPaths') as FormArray;
249
    return this.indicatorFb.get('indicatorPaths') as FormArray;
253 250
  }
254 251

  
255 252
  public getParameters(index: number): FormArray {
......
274 271
  }
275 272

  
276 273
  public createIndicatorOpen() {
274
    this.indicator = null;
277 275
    this.indicatorFb = this.fb.group({
276
      id: this.fb.control(null),
278 277
      name: this.fb.control('', Validators.required),
279 278
      description: this.fb.control(''),
279
      isPublic: this.fb.control(false),
280
      isActive: this.fb.control(false),
281
      urls: this.fb.array([]),
280 282
      width: this.fb.control('small', Validators.required),
281
      urls: this.fb.array([]),
282 283
    });
283 284
    this.addUrl();
284
    this.createIndicatorModal.alertTitle = 'Create a new chart Indicator';
285
    this.createIndicatorModal.cancelButtonText = 'Cancel';
286
    this.createIndicatorModal.okButtonText = 'Create';
287
    this.createIndicatorModal.okButtonLeft = false;
288
    this.createIndicatorModal.alertMessage = false;
289
    this.createIndicatorModal.open();
285
    this.editIndicatorModal.alertTitle = 'Create a new chart Indicator';
286
    this.editIndicatorModal.cancelButtonText = 'Cancel';
287
    this.editIndicatorModal.okButtonText = 'Create';
288
    this.editIndicatorModal.okButtonLeft = false;
289
    this.editIndicatorModal.alertMessage = false;
290
    this.editIndicatorModal.stayOpen = true;
291
    this.editIndicatorModal.open();
290 292
  }
291 293

  
292 294
  public createIndicator() {
......
295 297
      this.indicatorFb.value.description,
296 298
      'chart',
297 299
      this.indicatorFb.value.width,
298
      false,
299
      false,
300
      this.indicatorFb.value.isActive,
301
      this.indicatorFb.value.isPublic,
300 302
      []
301 303
    );
302 304
    this.indicatorFb.value.urls.forEach(url => {
......
335 337
        parameters: parameters
336 338
      }));
337 339
    });
338
    this.editIndicatorFb = this.fb.group({
340
    this.indicatorFb = this.fb.group({
339 341
      id: this.fb.control(this.indicator._id),
340 342
      name: this.fb.control(this.indicator.name, Validators.required),
341 343
      description: this.fb.control(this.indicator.description),
......
344 346
      indicatorPaths: indicatorPaths,
345 347
      width: this.fb.control(this.indicator.width, Validators.required),
346 348
    });
347
    this.editIndicatorModal.cancelButtonText = 'Cancel';
348
    this.editIndicatorModal.okButtonText = 'Save Changes';
349
    this.editIndicatorModal.okButtonLeft = false;
350
    this.editIndicatorModal.alertMessage = false;
351
    this.editIndicatorModal.open();
352
    setTimeout(() => {
353
      this.indicator.indicatorPaths.forEach(indicatorPath => {
354
        indicatorPath.safeResourceUrl = this.getUrlByStakeHolder(indicatorPath)
355
      });
356
    }, (index === -1)?500:0);
349
    if(index === -1) {
350
      this.editIndicatorModal.okButtonText = 'Save';
351
      this.editIndicatorModal.stayOpen = false;
352
    } else {
353
      this.editIndicatorModal.cancelButtonText = 'Cancel';
354
      this.editIndicatorModal.okButtonText = 'Save Changes';
355
      this.editIndicatorModal.okButtonLeft = false;
356
      this.editIndicatorModal.alertMessage = false;
357
      this.editIndicatorModal.open();
358
    }
359
    this.indicator.indicatorPaths.forEach(indicatorPath => {
360
      indicatorPath.safeResourceUrl = this.getUrlByStakeHolder(indicatorPath)
361
    });
357 362
  }
358 363

  
359 364
  saveIndicator() {
360
    this.indicator = this.indicatorUtils.generateIndicatorByForm(this.editIndicatorFb.value, this.indicator.indicatorPaths);
361
    let path = [
362
      this.stakeholder._id,
363
      this.stakeholder.topics[this.topicIndex]._id,
364
      this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex]._id,
365
      this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id
366
    ];
367
    this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.indicator, path).subscribe(indicator => {
368
      if (this.index !== -1) {
369
        this.charts[this.index] = indicator;
370
      } else {
371
        this.charts.push(indicator);
372
      }
373
      this.filterCharts();
374
      this.stakeholderService.setStakeholder(this.stakeholder);
375
    });
365
    if(this.indicator) {
366
      this.indicator = this.indicatorUtils.generateIndicatorByForm(this.indicatorFb.value, this.indicator.indicatorPaths);
367
      let path = [
368
        this.stakeholder._id,
369
        this.stakeholder.topics[this.topicIndex]._id,
370
        this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex]._id,
371
        this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id
372
      ];
373
      this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.indicator, path).subscribe(indicator => {
374
        if (this.index !== -1) {
375
          this.charts[this.index] = indicator;
376
        } else {
377
          this.charts.push(indicator);
378
        }
379
        this.filterCharts();
380
        this.stakeholderService.setStakeholder(this.stakeholder);
381
        this.indicatorFb = null;
382
      }, error => {
383
        this.indicatorFb = null;
384
      });
385
    } else {
386
      this.createIndicator();
387
    }
376 388
  }
377 389

  
378 390
  reorderIndicators(type: string, indicatorIds: string[]) {
......
395 407
  }
396 408

  
397 409
  refreshIndicator(index: number) {
398
    this.indicator = this.indicatorUtils.generateIndicatorByForm(this.editIndicatorFb.value, this.indicator.indicatorPaths);
410
    this.indicator = this.indicatorUtils.generateIndicatorByForm(this.indicatorFb.value, this.indicator.indicatorPaths);
399 411
    this.indicator.indicatorPaths.forEach(indicatorPath => {
400 412
      indicatorPath.safeResourceUrl = this.getUrlByStakeHolder(indicatorPath)
401 413
    });

Also available in: Unified diff