Project

General

Profile

« Previous | Next » 

Revision 57594

[Monitor Dashboard]: Add delete functionality on elements. Add docs on components.

View differences:

modules/uoa-monitor-portal/trunk/monitor_dashboard/src/app/services/stakeholder.service.ts
42 42
      '/indicator/save', indicator);
43 43
  }
44 44

  
45
  deleteElement(url: string, path: string[]): Observable<boolean> {
45
  deleteElement(url: string, path: string[]): Observable<any> {
46 46
    path = HelperFunctions.encodeArray(path);
47
    return this.http.delete<boolean>(url + '/' + path.join('/'))
47
    return this.http.delete<any>(url + '/' + path.join('/'))
48 48
  }
49 49

  
50 50
  getStakeholderAsObservable(): Observable<Stakeholder> {
modules/uoa-monitor-portal/trunk/monitor_dashboard/src/app/home/home.component.ts
146 146
  }
147 147

  
148 148
  deleteTopic() {
149

  
149
    let path = [
150
      this.stakeholder.alias,
151
      this.stakeholder.topics[this.index].alias
152
    ];
153
    this.stakeholderService.deleteElement(this.properties.monitorServiceAPIURL, path).subscribe(stakeholder => {
154
      this.stakeholderService.setStakeholder(stakeholder);
155
      UIkit.notification('Topic has been successfully deleted', {
156
        status: 'success',
157
        timeout: 3000,
158
        pos: 'top-left'
159
      });
160
      this.hide(this.element);
161
    }, error => {
162
      UIkit.notification(error.error.message, {
163
        status: 'danger',
164
        timeout: 3000,
165
        pos: 'top-left'
166
      });
167
      this.hide(this.element);
168
    });
150 169
  }
151 170
}
modules/uoa-monitor-portal/trunk/monitor_dashboard/src/app/library/sharedComponents/sidebar/sideBar.service.ts
12 12
  private openSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
13 13

  
14 14
  /**
15
   *  Set this variable to false in pages when it is not needed to have sidebar on Init
15
   *  Set this variable to false on Init of components that is not needed to have sidebar
16 16
   *  and on Destroy set this to true.
17 17
   */
18 18
  private hasSidebarSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(true);
modules/uoa-monitor-portal/trunk/monitor_dashboard/src/app/topic/indicators.component.html
18 18
        <label>Privacy:</label>
19 19
        <select class="uk-select uk-form-small uk-margin-small-left"
20 20
                (ngModelChange)="onPrivacyChange($event)"
21
                [(ngModel)]="isPublic">
21
                [(ngModel)]="privacy">
22 22
          <option [value]="'all'">All</option>
23 23
          <option [value]="'public'">Public</option>
24 24
          <option [value]="'private'">Private</option>
......
28 28
        <label>Status:</label>
29 29
        <select class="uk-select uk-form-small uk-margin-small-left"
30 30
                (ngModelChange)="onStatusChange($event)"
31
                [(ngModel)]="isActive">
31
                [(ngModel)]="status">
32 32
          <option [value]="'all'">All</option>
33 33
          <option [value]="'active'">Active</option>
34 34
          <option [value]="'inactive'">Inactive</option>
......
51 51
      </div>
52 52
    </div>
53 53
  </div>
54
  <div *ngIf="stakeholder" id="page_content_inner">
54
  <div *ngIf="stakeholder && canEdit" id="page_content_inner">
55 55
    <div class="uk-child-width-1-2 uk-flex-middle" uk-grid>
56 56
      <div>
57 57
        <ul id="breadcrumbs">
58 58
          <li><span>{{stakeholder.topics[topicIndex].name}}</span></li>
59
          <li><span>{{stakeholder.topics[topicIndex].categories[categoryIndex].name}}</span></li>
60 59
          <li>
60
            <span>{{stakeholder.topics[topicIndex].categories[categoryIndex].name}}</span></li>
61
          <li>
61 62
            <span class="md-color-blue-900 uk-text-bold">
62 63
              {{stakeholder.topics[topicIndex].categories[categoryIndex].subCategories[subcategoryIndex].name}}
63 64
            </span>
modules/uoa-monitor-portal/trunk/monitor_dashboard/src/app/topic/topic.component.ts
18 18
  public properties: EnvProperties;
19 19
  public loading: boolean = true;
20 20
  public stakeholder: Stakeholder;
21
  /**
22
   * Current topic
23
   **/
21 24
  public topicIndex: number = -1;
22 25
  public topic: Topic = null;
26

  
27
  /**
28
   * categoryIndex: Current category to be edited, selectedCategoryIndex: selected on menu(opened)
29
   */
23 30
  public categoryIndex: number = -1;
24 31
  public selectedCategoryIndex: number = -1;
25 32
  public copyCategory: Category = null;
33
  /**
34
   * Current Subcategory to be edited
35
   */
26 36
  public subCategoryIndex: number = -1;
27 37
  public copySubCategory: SubCategory = null;
38
  /**
39
   * Current drop element and index of topic, category or subcategory to be deleted.
40
   */
41
  public element: any;
42
  public index: number;
43
  /**
44
   * Check form validity
45
   */
28 46
  public valid = true;
29
  public edit: boolean = false;
30 47
  public toggle: boolean = false;
31 48

  
32
  public element: any;
33
  public index: number;
34

  
35 49
  @ViewChild('deleteTopicModal') deleteTopicModal: AlertModal;
36 50
  @ViewChild('deleteCategoryModal') deleteCategoryModal: AlertModal;
37 51
  @ViewChild('deleteSubcategoryModal') deleteSubcategoryModal: AlertModal;
......
72 86
  }
73 87

  
74 88
  public hide(element) {
75
    this.edit = false;
76 89
    UIkit.drop(element).hide();
77 90
  }
78 91

  
79 92
  public show(element) {
80
    this.edit = true;
81 93
    UIkit.drop(element).show();
82 94
  }
83 95

  
96
  public editTopicOpen(element) {
97
    if(element.className.indexOf('uk-open') !== -1) {
98
      this.hide(element);
99
    } else {
100
      this.topic = HelperFunctions.copy(this.stakeholder.topics[this.topicIndex]);
101
      this.valid = true;
102
      this.show(element);
103
    }
104
  }
105

  
106
  public saveTopic(element) {
107
    if(this.topic.name && this.topic.name !== ''
108
      && this.topic.description && this.topic.description !== '') {
109
      if(!this.topic.alias) {
110
        this.topic.alias = this.topic.name.toLowerCase().trim();
111
      }
112
      this.stakeholder.topics[this.topicIndex] = HelperFunctions.copy(this.topic);
113
      this.save('Topic has been successfully saved', element, true);
114
    } else {
115
      this.valid = false;
116
    }
117
  }
118

  
119
  public deleteTopicOpen(element) {
120
    this.deleteOpen('topic', this.deleteTopicModal, element, this.topicIndex);
121
  }
122

  
123
  public deleteTopic() {
124
    let path: string[] = [
125
      this.stakeholder.alias,
126
      this.stakeholder.topics[this.topicIndex].alias
127
    ];
128
    this.delete('Topic has been successfully be deleted', path, true);
129
  }
130

  
84 131
  public toggleCategory(index: number) {
85 132
   if(this.selectedCategoryIndex !== index) {
86 133
      this.selectedCategoryIndex = index;
......
126 173
  }
127 174

  
128 175
  public deleteCategory() {
129
    this.stakeholder.topics[this.topicIndex].categories.splice(this.index, 1);
130
    this.stakeholderService.saveStakeholder(this.properties.monitorServiceAPIURL, this.stakeholder).subscribe(stakeholder => {
131
      this.stakeholderService.setStakeholder(stakeholder);
132
      UIkit.notification('Category has been successfully deleted', {
133
        status: 'success',
134
        timeout: 3000,
135
        pos: 'top-left'
136
      });
137
      this.hide(this.element);
138
    }, error => {
139
      UIkit.notification(error.error.message, {
140
        status: 'danger',
141
        timeout: 3000,
142
        pos: 'top-left'
143
      });
144
      this.hide(this.element);
145
    });
176
    let path: string[] = [
177
      this.stakeholder.alias,
178
      this.stakeholder.topics[this.topicIndex].alias,
179
      this.stakeholder.topics[this.topicIndex].categories[this.index].alias
180
    ];
181
    this.delete('Category has been successfully be deleted', path);
146 182
  }
147 183

  
148 184
  public editSubCategoryOpen(index:number = -1, element = null) {
......
185 221
  }
186 222

  
187 223
  public deleteSubcategory() {
188
    this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories.
189
    splice(this.index, 1);
190
    this.stakeholderService.saveStakeholder(this.properties.monitorServiceAPIURL, this.stakeholder).subscribe(stakeholder => {
191
      this.stakeholderService.setStakeholder(stakeholder);
192
      UIkit.notification('Subcategory has been successfully deleted', {
193
        status: 'success',
194
        timeout: 3000,
195
        pos: 'top-left'
196
      });
197
      this.hide(this.element);
198
    }, error => {
199
      UIkit.notification(error.error.message, {
200
        status: 'danger',
201
        timeout: 3000,
202
        pos: 'top-left'
203
      });
204
      this.hide(this.element);
205
    });
224
    let path: string[] = [
225
      this.stakeholder.alias,
226
      this.stakeholder.topics[this.topicIndex].alias,
227
      this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].alias,
228
      this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories[this.index].alias
229
    ];
230
    this.delete('Subcategory has been successfully be deleted', path);
206 231
  }
207 232

  
208
  public editTopicOpen(element) {
209
    if(element.className.indexOf('uk-open') !== -1) {
210
      this.hide(element);
211
    } else {
212
      this.topic = HelperFunctions.copy(this.stakeholder.topics[this.topicIndex]);
213
      this.valid = true;
214
      this.show(element);
215
    }
216
  }
217

  
218
  public saveTopic(element) {
219
    if(this.topic.name && this.topic.name !== ''
220
      && this.topic.description && this.topic.description !== '') {
221
      if(!this.topic.alias) {
222
        this.topic.alias = this.topic.name.toLowerCase().trim();
223
      }
224
      this.stakeholder.topics[this.topicIndex] = HelperFunctions.copy(this.topic);
225
      this.save('Topic has been successfully saved', element, true);
226
    } else {
227
      this.valid = false;
228
    }
229
  }
230

  
231
  public deleteTopicOpen(element) {
232
    this.deleteOpen('topic', this.deleteTopicModal, element, this.topicIndex);
233
  }
234

  
235
  public deleteTopic() {
236
    this.stakeholder.topics.splice(this.index, 1);
237
    this.stakeholderService.saveStakeholder(this.properties.monitorServiceAPIURL, this.stakeholder).subscribe(stakeholder => {
238
      this.stakeholderService.setStakeholder(stakeholder);
239
      UIkit.notification('Topic has been successfully deleted', {
240
        status: 'success',
241
        timeout: 3000,
242
        pos: 'top-left'
243
      });
244
      this.hide(this.element);
245
      this.back();
246
    }, error => {
247
      UIkit.notification(error.error.message, {
248
        status: 'danger',
249
        timeout: 3000,
250
        pos: 'top-left'
251
      });
252
      this.hide(this.element);
253
    });
254
  }
255

  
256 233
  private navigateToError() {
257 234
    this.router.navigate(['/error'], {queryParams: {'page': this.router.url}});
258 235
  }
......
293 270
    });
294 271
  }
295 272

  
273
  private delete(message: string, path: string[], redirect = false) {
274
    this.stakeholderService.deleteElement(this.properties.monitorServiceAPIURL, path).subscribe(stakeholder => {
275
      this.stakeholderService.setStakeholder(stakeholder);
276
      UIkit.notification(message, {
277
        status: 'success',
278
        timeout: 3000,
279
        pos: 'top-left'
280
      });
281
      if(redirect) {
282
        this.back();
283
      }
284
      this.hide(this.element);
285
    }, error => {
286
      UIkit.notification(error.error.message, {
287
        status: 'danger',
288
        timeout: 3000,
289
        pos: 'top-left'
290
      });
291
      this.hide(this.element);
292
    });
293
  }
294

  
296 295
  back() {
297 296
    this.router.navigate(['../'], {
298 297
      relativeTo: this.route
modules/uoa-monitor-portal/trunk/monitor_dashboard/src/app/topic/indicators.component.ts
18 18
  @Input()
19 19
  public stakeholder: Stakeholder = null;
20 20
  public indicatorUtils: IndicatorUtils = new IndicatorUtils();
21
  /**
22
   * All charts and numbers
23
   */
21 24
  public charts: Indicator[] = [];
22 25
  public numbers: Indicator[] = [];
26
  /**
27
   * Displayed chart and numbers base on Top filters
28
   */
23 29
  public displayCharts: Indicator[] = [];
24 30
  public displayNumbers: Indicator[] = [];
31
  /**
32
   * Top filters
33
   */
25 34
  public chartType: string = 'all';
26
  public isPublic: string = 'all';
27
  public isActive: string = 'all';
35
  public privacy: string = 'all';
36
  public status: string = 'all';
28 37
  public keyword: string = null;
38
  /**
39
   * Grid or List View
40
   */
29 41
  public grid: boolean = true;
30 42

  
31 43
  constructor(private sideBarService: SideBarService) {}
......
34 46
  }
35 47

  
36 48
  ngOnChanges(changes: SimpleChanges): void {
37
    if(this.stakeholder) {
49
    if(this.canEdit) {
38 50
      this.charts = this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].
39 51
        subCategories[this.subcategoryIndex].charts;
40 52
      this.displayCharts = this.filterChartType(this.filterPrivacy(
41
        this.filterStatus(this.filterByKeyword(this.charts, this.keyword), this.isActive),
42
        this.isPublic),
53
        this.filterStatus(this.filterByKeyword(this.charts, this.keyword), this.status),
54
        this.privacy),
43 55
        this.chartType
44 56
      );
45 57
      this.numbers = this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].
46 58
        subCategories[this.subcategoryIndex].numbers;
47 59
      this.displayNumbers = this.filterPrivacy(this.filterStatus(
48 60
        this.filterByKeyword(this.numbers, this.keyword),
49
        this.isActive),
50
        this.isPublic);
61
        this.status),
62
        this.privacy);
51 63
    }
52 64
  }
53 65

  
......
107 119
    return this.sideBarService.open;
108 120
  }
109 121

  
122
  get canEdit() {
123
    return this.stakeholder &&
124
      this.stakeholder.topics[this.topicIndex] &&
125
      this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex] &&
126
      this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex];
127
  }
128

  
110 129
  public toggleOpen(event = null) {
111 130
    if (!event) {
112 131
      this.sideBarService.setOpen(!this.open);

Also available in: Unified diff