Project

General

Profile

« Previous | Next » 

Revision 50611

1. Created 'entity' folder : 'entity' page and form go there
2. Created 'page' folder : 'page' page and form go there

View differences:

modules/uoa-admin-portal/trunk/app/pages/helpcontent/page-form.component.html
1
<form [formGroup]="myForm">
2
    <div class="form-group" [ngClass]="{'has-error':!myForm.controls.route.valid && myForm.controls.route.dirty}">
3
        <label for="pageRouteTag">Page Route</label>
4
        <input type="text" class="form-control" formControlName="route" id="pageRouteTag" placeholder="Page Route">
5
    </div>
6
    <div class="form-group" [ngClass]="{'has-error':!myForm.controls.name.valid && myForm.controls.name.dirty}">
7
        <label for="pageNameTag">Page Name</label>
8
        <input type="text" class="form-control" formControlName="name" id="pageNameTag" placeholder="Page Name">
9
    </div>
10
    <div *ngIf="!type" class="form-group" [ngClass]="{'has-error':!myForm.controls.type.valid && myForm.controls.type.dirty}">
11
        <label for="typeTag">Select Type</label>
12
        <select formControlName="type" id="typeTag" class="form-control">
13
            <option [value]="'search'">search</option>
14
            <option [value]="'link'">link</option>
15
            <option [value]="'share'">share</option>
16
        </select>
17
    </div>
18

  
19
    <div formArrayName="entities" class="form-group">
20
        <label for="entityNameTag">Entity Name</label>
21
        <div id="entityNameTag">
22
          <pre class="card card-block card-header"><span *ngFor="let entity of myForm.value.entities; let i=index">{{entity.name}}<span *ngIf="i<(myForm.value.entities.length-1)">, </span></span></pre>
23

  
24
          <button type="button" (click)="toggle()">Add / Remove entities</button>
25
          <ng-container *ngIf="!myForm.value.isCollapsed" >
26
          <div *ngFor="let entity of getKeys(allEntities)">
27
            <span>
28
              <span *ngIf="allEntities.get(entity)" class="activated" >
29
                  <input (click)="toggleEntity(false,[entity._id], entity)" class="deactivate" src="imgs/delete-icon.png" title="Disable" width="20" type="image" height="20">
30
              </span>
31
              <span *ngIf="!allEntities.get(entity)" class="deactivated" >
32
                  <input (click)="toggleEntity(true,[entity._id], entity)" class="deactivate" src="imgs/add-icon.png" title="Enable" width="20" type="image" height="20">
33
              </span>
34
              {{entity.name}}
35
            </span>
36
          </div>
37
        </ng-container>
38

  
39
        </div>
40
    </div>
41

  
42
    <input type="hidden" formControlName="_id">
43
</form>
modules/uoa-admin-portal/trunk/app/pages/helpcontent/entity-form.component.html
1
<form [formGroup]="myForm">
2
    <div class="form-group" [ngClass]="{'has-error':!myForm.controls.name.valid && myForm.controls.name.dirty}">
3
        <label for="entityNameTag">Entity Name</label>
4
        <input type="text" class="uk-input uk-width-medium" formControlName="name" id="entityNameTag" placeholder="Entity Name">
5
    </div>
6
    <div class="form-group" [ngClass]="{'has-error':!myForm.controls.pid.valid && myForm.controls.pid.dirty}">
7
        <label for="entityPidTag">Entity persistent id for portal</label>
8
        <input type="text" class="uk-input uk-width-medium" formControlName="pid" id="entityPidTag" placeholder="Entity Pid">
9
    </div>
10

  
11
<!--
12
    <div ngModelGroup="phoneNumbers">
13
      <h3>Phone numbers</h3>
14
      <div *ngFor="let phoneId of phoneNumberIds; let i=index;">
15
        <label>Phone number {{i + 1}}</label>
16
        <input type="text" name="phoneNumber[{{phoneId}}]" #phoneNumber="ngModel" ngModel/>
17
        <button type="button" (click)="remove(i); myForm.control.markAsTouched()">remove</button>
18
      </div>
19
      <button type="button" (click)="add(); myForm.control.markAsTouched()">Add phone number</button>
20
    </div>
21
-->
22

  
23
<!-- <div class="form-group" [ngClass]="{'has-error':!myForm.controls.name.valid && myForm.controls.entities.dirty}">
24
  <div *ngFor="let entity of entities; let i=index;">
25
    <label>Entity {{i + 1}}</label>
26
    <input type="text" name="entities[{{entity}}]" class="form-control" formControlName="entity"/>
27
  </div>
28
</div> -->
29

  
30

  
31
    <input type="hidden" formControlName="_id">
32
</form>
33
<!--<pre>-->
34
<!--{{myForm.value | json}}-->
35
<!--</pre>-->
modules/uoa-admin-portal/trunk/app/pages/helpcontent/pages.component.ts
1
/**
2
 * Created by stefania on 7/13/17.
3
 */
4
import { Component, ViewChild, OnInit } from '@angular/core';
5
import { ActivatedRoute } from "@angular/router";
6
import { HelpContentService } from "../../services/help-content.service";
7
import { FormGroup } from "@angular/forms";
8
import { ModalFormComponent } from "../modal-form.component";
9
import { DeleteConfirmationDialogComponent } from "../delete-confirmation-dialog.component";
10
import { PageFormComponent } from "./page-form.component";
11
import { CheckPage, Page } from "../../domain/page";
12
import { Community } from "../../domain/community";
13
import { Entity } from "../../domain/entity";
14

  
15
@Component({
16
    selector: 'pages',
17
    templateUrl: './pages.component.html',
18
})
19

  
20
export class PagesComponent implements OnInit {
21

  
22
    // @ViewChild(ModalFormComponent)
23
    @ViewChild('saveModal')
24
    public modal:ModalFormComponent;
25

  
26
    @ViewChild('updateModal')
27
    public updateModal:ModalFormComponent;
28

  
29
    @ViewChild('deleteConfirmationModal')
30
    public deleteConfirmationModal : DeleteConfirmationDialogComponent;
31

  
32
    @ViewChild(PageFormComponent)
33
    public formComponent : PageFormComponent;
34

  
35
    public checkboxes : CheckPage[] = [];
36

  
37
    public pages : Page[] = [];
38
    public pageWithDivIds: string[] = [];
39

  
40
    public errorMessage: string;
41

  
42
    public formGroup : FormGroup;
43

  
44
    private searchText : RegExp = new RegExp('');
45

  
46
    public communities: Community[] = [];
47

  
48
    public selectedCommunityPid: string;
49

  
50
    public pagesType: string;
51

  
52
    ngOnInit() {
53
        this.formGroup = this.formComponent.form;
54
//        this.getCommunities();
55

  
56
        this.route.queryParams.subscribe(params => {
57
          this.pagesType = "";
58
          if(params['type']) {
59
            this.pagesType = params['type'];
60
          }
61
          this.getCommunities();
62
        });
63
    }
64

  
65
    constructor(private route: ActivatedRoute, private _helpContentService: HelpContentService) {}
66

  
67
    getPages(community_pid: string) {
68
        let self = this;
69

  
70
        if(this.pagesType) {
71
          this._helpContentService.getCommunityPagesByType(community_pid, "?page_type="+this.pagesType).subscribe(
72
              pages => {
73
                self.pagesReturned(pages);
74
              },
75
              error => this.handleError('System error retrieving pages', error));
76
        } else {
77
          this._helpContentService.getCommunityPages(community_pid).subscribe(
78
              pages => {
79
                self.pagesReturned(pages);
80
              },
81
              error => this.handleError('System error retrieving pages', error));
82
        }
83
    }
84

  
85
    getPagesWithDivIds(community_pid: string) {
86
      let self = this;
87
      this._helpContentService.getPagesWithDivIds(community_pid).subscribe(
88
          pages => {
89
            self.pageWithDivIds = pages[community_pid];
90
          },
91
          error => this.handleError('System error retrieving pages', error));
92
    }
93

  
94
    pagesReturned(pages: Page[]) {
95
      this.pages = pages;
96
      this.checkboxes = [];
97

  
98
      pages.forEach(_ => {
99
          this.checkboxes.push(<CheckPage>{page : _, checked : false});
100
      });
101
    }
102

  
103
    getCommunities() {
104
        let self = this;
105
        this._helpContentService.getCommunities().subscribe(
106
            communities => {
107
                self.communities = communities;
108
                self.selectedCommunityPid = self.communities[0].pid;
109
                self.getPages(self.selectedCommunityPid);
110
                self.getPagesWithDivIds(self.selectedCommunityPid);
111
        },
112
        error => this.handleError('System error retrieving communities', error));
113
    }
114

  
115
    public showModal():void {
116
        this.modal.showModal();
117
    }
118

  
119
    public toggleCheckBoxes(event) {
120
        this.checkboxes.forEach(_ => _.checked = event.target.checked);
121
    }
122

  
123
    public applyCheck(flag : boolean) {
124
      console.info("applyCheck "+flag);
125
        this.checkboxes.forEach(_ => _.checked = flag);
126
    }
127

  
128
    public getSelectedPages() : string[] {
129
        return this.checkboxes.filter(page => page.checked == true).map(checkedPage => checkedPage.page).map(res => res._id);
130
    }
131

  
132
    private deletePagesFromArray(ids : string[]) : void {
133
        for(let id of ids) {
134
            let i = this.checkboxes.findIndex(_ => _.page._id == id);
135
            this.checkboxes.splice(i, 1);
136
        }
137
    }
138

  
139
    public confirmDeletePage(id : string) {
140
        this.deleteConfirmationModal.ids = [id];
141
        this.deleteConfirmationModal.showModal();
142
    }
143

  
144
    public confirmDeleteSelectedPages() {
145
        this.deleteConfirmationModal.ids = this.getSelectedPages();
146
        this.deleteConfirmationModal.showModal();
147
    }
148

  
149
    public confirmedDeletePages(ids : string[]) {
150
        this._helpContentService.deletePages(ids).subscribe(
151
            _ => this.deletePagesFromArray(ids),
152
            error => this.handleError('System error deleting the selected pages', error)
153
        );
154
    }
155

  
156
    public editPage(i : number) {
157
        let page : Page = this.checkboxes[i].page;
158
        this.formGroup.patchValue(page);
159
        const entityFGs = (page.entities as Entity[]).map(entity => this.formComponent._fb.group(entity));
160
        const entityFormArray = this.formComponent._fb.array(entityFGs);
161
        this.formGroup.setControl('entities', entityFormArray);
162
        console.info(this.formGroup.value);
163
        this.updateModal.showModal();
164
    }
165

  
166
    public pageSavedSuccessfully(page: Page) {
167
        this.checkboxes.push(<CheckPage>{page : page, checked : false});
168
        console.info("checkboxes length: "+this.checkboxes.length);
169
        this.applyCheck(false);
170
    }
171

  
172
    public pageUpdatedSuccessfully(page : Page) {
173
      console.info(page._id);
174
      console.info(this.checkboxes.find(checkItem => (checkItem.page._id == page._id)));
175
      console.info(page.entities);
176
        this.checkboxes.find(checkItem => checkItem.page._id==page._id).page = page;
177
        this.applyCheck(false);
178
    }
179

  
180
    public filterBySearch(text : string) {
181
        this.searchText = new RegExp(text,'i');
182
        this.applyFilter();
183
    }
184

  
185
    public applyFilter() {
186
        this.checkboxes = [];
187
        this.pages.filter(item => this.filterPages(item)).forEach(
188
            _ => this.checkboxes.push(<CheckPage>{page: _, checked: false})
189
        );
190
    }
191

  
192
    public filterPages(page : Page) : boolean {
193
        let textFlag = this.searchText.toString() == '' || (page.route + ' ' +page.name).match(this.searchText) != null;
194
        return textFlag;
195
    }
196

  
197
    handleError(message: string, error) {
198
        if(error == null) {
199
            this.formComponent.reset();
200
        }
201
        this.errorMessage = message + ' (Server responded: ' + error + ')';
202
    }
203

  
204

  
205

  
206
    public filterByCommunity(event: any) {
207
        this.selectedCommunityPid = event.target.value;
208
        this.applyCommunityFilter(this.selectedCommunityPid);
209
    }
210

  
211
    public applyCommunityFilter(community_pid: string) {
212
        this.getPages(community_pid);
213
        this.getPagesWithDivIds(community_pid);
214
    }
215

  
216
    public togglePages(status : boolean, ids : string[]) {
217
        this._helpContentService.togglePages(this.selectedCommunityPid,ids,status).subscribe(
218
            () => {
219
                for(let id of ids) {
220
                //     let i = this.checkboxes.findIndex(_ => _.page._id == id);
221
                //     this.checkboxes[i].page.isEnabled=status;
222
                // }
223
                  let i = this.checkboxes.findIndex(_ => _.page._id == id);
224
                  this.checkboxes[i].page.isEnabled=status;
225
                }
226
                this.applyCheck(false);
227
            },
228
            error => this.handleError('System error changing the status of the selected page(s)', error)
229
        );
230
    }
231

  
232

  
233
}
modules/uoa-admin-portal/trunk/app/pages/helpcontent/entities.component.html
1
<div id="entities" class="uk-container">
2

  
3
        <div class="menubar ">
4

  
5
            <div class="entity-title uk-article-title  ">Entities</div>
6
            <form target="BSFormPanel_Admin_1" class="search">
7
                <input #inputstring (keyup.enter)="filterBySearch(inputstring.value)" placeholder="Entity name..." type="text" class="uk-input uk-width-medium"/>
8
                <button class="uk-button" type="submit">Search</button>
9
            </form>
10
            <a (click)="showModal()" class="uk-button uk-button-primary uk-float-right"><i></i> New Entity </a>
11
        </div>
12

  
13
        <div class="content-wrapper" id="contentWrapper">
14
            <div>
15
                <div class="contentPanel">
16
                    <div class="uk-alert-danger" uk-alert style="display: none;" aria-hidden="true">
17
                        <span></span><span></span><span></span></div>
18
                    <div class="uk-alert-success" uk-alert style="display: none;" aria-hidden="true">
19
                        <span></span><span></span><span></span></div>
20
                    <div class="uk-alert" uk-alert style="display: none;" aria-hidden="true"><span></span><span></span><span></span></div>
21

  
22
                    <div class="page-controls">
23
                        <div class="  filters ">
24
                            <div class="show-options uk-float-right">
25
                              <button class="uk-button" type="button"> Bulk Actions</button>
26
                              <div uk-dropdown="mode: click">
27
                                <ul class="uk-nav uk-dropdown-nav">
28
                                    <li><a (click)="toggleEntities(true, getSelectedEntities())"><i></i> Activate </a></li>
29
                                    <li><a (click)="toggleEntities(false, getSelectedEntities())"><i></i> Deactivate </a></li>
30
                                    <li><a (click)="confirmDeleteSelectedEntities()"><i></i> Delete </a></li>
31
                                </ul>
32
                              </div>
33
                                <!--div class="btn-group"><a href="javascript:;" class="btn dropdown-toggle"
34
                                                          data-toggle="dropdown"><i></i> Bulk Actions <span
35
                                        class="caret"></span></a>
36
                                    <ul class="dropdown-menu">
37
                                        <li><a (click)="confirmDeleteSelectedEntities()"><i></i> Delete </a></li>
38
                                    </ul>
39
                                </div-->
40
                            </div>
41
                        </div>
42
                    </div>
43

  
44
                    <div>
45
                        <div class="gwt-HTML">
46
                            <div class="row users-list">
47
                                <div class="col-md-12">
48

  
49
                                  <div class="filters marginBottom20">
50
                                      <div class="links form-group form-inline">
51
                                          <span>Filter by community:</span>
52
                                          <select class="uk-select uk-width-medium" (change)="filterByCommunity($event)">
53
                                              <!--option value="">-- none selected --</option-->
54
                                              <option *ngFor="let community of communities" value="{{community.pid}}">{{community.name}}</option>
55
                                          </select>
56
                                      </div>
57
                                  </div>
58
                                  <table class="uk-table uk-table-striped">
59
                                    <thead>
60
                                        <tr>
61
                                            <th><input id="allEntityCheckbox" type="checkbox" (change)="toggleCheckBoxes($event)"></th>
62
                                            <th>Name</th>
63
                                            <th>State</th>
64
                                            <th>Actions</th>
65
                                        </tr>
66
                                    </thead>
67
                                    <tbody >
68
                                        <tr *ngFor="let check of checkboxes; let i=index">
69
                                            <td><input id="{{check.entity._id}}" class="checkBox" type="checkbox"
70
                                                                                name="entitiescb[]" value="{{check.entity._id}}" [(ngModel)]="check.checked">
71
                                            </td>
72
                                            <td>
73
                                                <div class="name" href="#">{{check.entity.name}}</div>
74
                                            </td>
75
                                            <td>
76
                                              <div *ngIf="check.entity.isEnabled" class="activated" >
77
                                                  <input (click)="toggleEntities(false,[check.entity._id])" class="deactivate" src="imgs/check-icon.png" title="Disable" width="20" type="image" height="20">
78
                                              </div>
79
                                              <div *ngIf="!check.entity.isEnabled" class="deactivated" >
80
                                                  <input (click)="toggleEntities(true,[check.entity._id])" class="deactivate" src="imgs/x-icon.png" title="Enable" width="20" type="image" height="20">
81
                                              </div>
82
                                            </td>
83
                                            <td>
84
                                                <div class="actions" href="#">
85
                                                    <input title="Edit" src="imgs/icn_edit.png" class="edit" type="image" (click)="editEntity(i)">
86
                                                    <input title="Delete" src="imgs/icn_trash.png" class="delete" type="image" (click)="confirmDeleteEntity(check.entity._id)">
87
                                                </div>
88
                                            </td>
89
                                        </tr>
90
                                    </tbody>
91
                                </table>
92

  
93
                                    <div *ngIf="checkboxes.length==0" class="col-md-12">
94
                                        <div class="uk-alert-warning" uk-alert>No entities found</div>
95
                                    </div>
96
                                </div>
97
                            </div>
98
                        </div>
99
                    </div>
100
                </div>
101
            </div>
102
        </div>
103
</div>
104
<modal-form #saveModal [saveText]="'Save'" [titleText]="'Add a new Entity'" [formGroup]="formGroup" [type]="'entity'"
105
            [isModalShown]="isModalShown" (emmitObject)="entitySavedSuccessfully($event)" (emmitError)="handleError($event)">
106
    <entity-form [group]="formGroup"></entity-form>
107
</modal-form>
108

  
109
<modal-form #updateModal [saveText]="'Update'" [titleText]="'Update Entity'" [formGroup]="formGroup" [type]="'entity'"
110
            [isModalShown]="isModalShown" (emmitObject)="entityUpdatedSuccessfully($event)" (emmitError)="handleError($event)">
111
    <entity-form [group]="formGroup"></entity-form>
112
</modal-form>
113
<modal-form #okModal [saveText]="'OK'" [titleText]="'Warning'" [type]="'none'"
114
            [isModalShown]="isModalShown" (emmitObject)="continueToggling($event)" (emmitError)="handleError($event)">
115
            This action will affect all search pages related to this entity!
116
            Pages' status will change to entity's status!
117
            Do you want to continue?
118
<modal-form>
119
<delete-confirmation-dialog #deleteConfirmationModal [isModalShown]="isModalShown" (emmitObject)="confirmedDeleteEntities($event)">
120
    Are you sure you want to delete the selected entity(-ies)?
121
</delete-confirmation-dialog>
modules/uoa-admin-portal/trunk/app/pages/helpcontent/pages.component.html
1
<!-- <div id="pages">
2
    <div id="content">
3
        <div class="menubar fixed">
4
            <div class="sidebar-toggler visible-xs">
5
                <i class="ion-navicon"></i>
6
            </div>
7

  
8
            <div class="page-title">Pages</div>
9
            <form target="BSFormPanel_Admin_1" class="search">
10
                <input #inputstring (keyup.enter)="filterBySearch(inputstring.value)" placeholder="Search pages (route, name)..." type="text"/>
11
                <input class="btn" type="submit">
12
            </form>
13
            <a (click)="showModal()" class="btn btn-success pull-right"><i></i> New Page </a>
14
        </div>
15

  
16
        <div class="content-wrapper" id="contentWrapper">
17
            <div>
18
                <div class="contentPanel">
19
                    <div class="alert alert-danger" style="display: none;" aria-hidden="true">
20
                        <span></span><span></span><span></span></div>
21
                    <div class="alert alert-success" style="display: none;" aria-hidden="true">
22
                        <span></span><span></span><span></span></div>
23
                    <div class="alert" style="display: none;" aria-hidden="true"><span></span><span></span><span></span></div>
24
                    <div class="row page-controls">
25
                        <div class="col-md-12 filters">
26
                            <div class="show-options">
27
                                <div class="btn-group"><a href="javascript:;" class="btn dropdown-toggle"
28
                                                          data-toggle="dropdown"><i></i> Bulk Actions <span
29
                                        class="caret"></span></a>
30
                                    <ul class="dropdown-menu">
31
                                        <li><a (click)="confirmDeleteSelectedPages()"><i></i> Delete </a></li>
32
                                    </ul>
33
                                </div>
34
                            </div>
35
                        </div>
36
                    </div>
37
                    <div>
38
                        <div class="gwt-HTML">
39
                            <div class="row users-list">
40
                                <div class="col-md-12">
41

  
42
                                  <div class="filters marginBottom20">
43
                                      <div class="links form-group form-inline">
44
                                          <div class="gwt-Label filterLabel">Filter by community:</div>
45
                                          <select class="input-xxlarge form-control" (change)="filterByCommunity($event)">
46
                                              <option *ngFor="let community of communities" value="{{community._id}}">{{community.name}}</option>
47
                                          </select>
48
                                      </div>
49
                                  </div>
50

  
51
                                    <div class="row headers">
52
                                        <div class="col-sm-1 header select-users"><input id="allPageCheckbox" type="checkbox" (change)="toggleCheckBoxes($event)">
53
                                        </div>
54
                                        <div class="col-sm-2 header hidden-xs"><label><a href="#">Route</a></label></div>
55
                                        <div class="col-sm-2 header hidden-xs"><label><a href="#">Name</a></label></div>
56
                                        <div class="col-sm-1 header hidden-xs"><label><a href="#">State</a></label></div>
57
                                        <div class="col-sm-1 header hidden-xs"><label><a href="#">Type</a></label></div>
58
                                        <div class="col-sm-3 header hidden-xs"><label><a href="#">Related Entities</a></label></div>
59
                                        <div class="col-sm-1 header hidden-xs"><label><a href="#">Actions</a></label></div>
60
                                        <div class="col-sm-1 header hidden-xs"><label><a href="#">Help Contents</a></label></div>
61
                                    </div>
62

  
63
                                    <ng-template [ngIf]="pagesCheckboxes && pagesCheckboxes.length>0">
64
                                        <div *ngFor="let check of pagesCheckboxes; let i=index" class="row user">
65
                                            <div class="col-sm-1 avatar"><input id="{{check.page._id}}" class="checkBox" type="checkbox"
66
                                                                                name="pagescb[]" value="{{check.page._id}}" [(ngModel)]="check.checked">
67
                                            </div>
68
                                            <div class="col-sm-2">
69
                                                <div class="route" href="#">{{check.page.route}}</div>
70
                                            </div>
71
                                            <div class="col-sm-2">
72
                                                <div class="name" href="#">{{check.page.name}}</div>
73
                                            </div>
74
                                            <div class="col-sm-1">
75
                                                <div *ngIf="check.page.isEnabled" class="activated" >
76
                                                    <input (click)="togglePage(false,[check.page._id])" class="deactivate" src="imgs/check-icon.png" title="Disable" width="20" type="image" height="20">
77
                                                </div>
78
                                                <div *ngIf="!check.page.isEnabled" class="deactivated" >
79
                                                    <input (click)="togglePage(true,[check.page._id])" class="deactivate" src="imgs/x-icon.png" title="Enable" width="20" type="image" height="20">
80
                                                </div>
81
                                            </div>
82
                                            <div class="col-sm-1">
83
                                                <div class="type" href="#">{{check.page.type}}</div>
84
                                            </div>
85
                                            <div class="col-sm-3">
86
                                                <div class="entities" href="#">
87
                                                  <span *ngFor="let entity of check.page.entities let i=index">{{entity.name}}<span *ngIf="i<(check.page.entities.length-1)">, </span></span>
88
                                                </div>
89
                                            </div>
90
                                            <div class="col-sm-1">
91
                                                <div class="actions" href="#">
92
                                                    <input title="Edit" src="imgs/icn_edit.png" class="edit" type="image" (click)="editPage(i)">
93
                                                    <input title="Delete" src="imgs/icn_trash.png" class="delete" type="image" (click)="confirmDeletePage(check.page._id)">
94
                                                </div>
95
                                            </div>
96
                                            <div class=col-sm-1>
97
                                              <a class="helpContents" [queryParams]="{community: selectedCommunityId, page: check.page._id}" routerLink="/pageContents">edit</a>
98
                                            </div>
99
                                        </div>
100
                                    </ng-template>
101
                                    <div *ngIf="pagesCheckboxes.length==0" class="col-md-12">
102
                                        <div class="alert alert-warning">No pages found</div>
103
                                    </div>
104
                                </div>
105
                            </div>
106
                        </div>
107
                    </div>
108
                </div>
109
            </div>
110
        </div>
111
    </div>
112
</div>
113
<modal-form #saveModal [saveText]="'Save'" [titleText]="'Add a new Page'" [formGroup]="formGroup" [type]="'page'"
114
            [isModalShown]="isModalShown" (emmitObject)="pageSavedSuccessfully($event)" (emmitError)="handleError($event)"
115
            [selectedCommunityId]="selectedCommunityId">
116
    <page-form [group]="formGroup" [selectedCommunityId]="selectedCommunityId" [type]="pagesType"></page-form>
117
</modal-form>
118

  
119
<modal-form #updateModal [saveText]="'Update'" [titleText]="'Update Page'" [formGroup]="formGroup" [type]="'page'"
120
            [isModalShown]="isModalShown" (emmitObject)="pageUpdatedSuccessfully($event)" (emmitError)="handleError($event)"
121
            [selectedCommunityId]="selectedCommunityId">
122
    <page-form [group]="formGroup" [selectedCommunityId]="selectedCommunityId" [type]="pagesType"></page-form>
123
</modal-form>
124

  
125
<delete-confirmation-dialog #deleteConfirmationModal [isModalShown]="isModalShown" (emmitObject)="confirmedDeletePages($event)">
126
    Are you sure you want to delete the selected page(s)?
127
</delete-confirmation-dialog> -->
128

  
129

  
130

  
131

  
132

  
133

  
134

  
135

  
136

  
137

  
138
<div id="pages" class="uk-container">
139

  
140
        <div class="menubar ">
141

  
142
            <div class="page-title uk-article-title  ">Pages</div>
143
            <form target="BSFormPanel_Admin_1" class="search">
144
                <input #inputstring (keyup.enter)="filterBySearch(inputstring.value)" placeholder="Page name..." type="text" class="uk-input uk-width-medium"/>
145
                <button class="uk-button" type="submit">Search</button>
146
            </form>
147
            <a (click)="showModal()" class="uk-button uk-button-primary uk-float-right"><i></i> New Page </a>
148
        </div>
149

  
150
        <div class="content-wrapper" id="contentWrapper">
151
            <div>
152
                <div class="contentPanel">
153
                    <div class="uk-alert-danger" uk-alert style="display: none;" aria-hidden="true">
154
                        <span></span><span></span><span></span></div>
155
                    <div class="uk-alert-success" uk-alert style="display: none;" aria-hidden="true">
156
                        <span></span><span></span><span></span></div>
157
                    <div class="uk-alert" uk-alert style="display: none;" aria-hidden="true"><span></span><span></span><span></span></div>
158

  
159
                    <div class="page-controls">
160
                        <div class="  filters ">
161
                            <div class="show-options uk-float-right">
162
                              <button class="uk-button" type="button"> Bulk Actions</button>
163
                              <div uk-dropdown="mode: click">
164
                                <ul class="uk-nav uk-dropdown-nav">
165
                                    <li><a (click)="togglePages(true, getSelectedPages())"><i></i> Activate </a></li>
166
                                    <li><a (click)="togglePages(false, getSelectedPages())"><i></i> Deactivate </a></li>
167
                                    <li><a (click)="confirmDeleteSelectedPages()"><i></i> Delete </a></li>
168
                                </ul>
169
                              </div>
170
                            </div>
171
                        </div>
172
                    </div>
173

  
174
                    <div>
175
                        <div class="gwt-HTML">
176
                            <div class="row users-list">
177
                                <div class="col-md-12">
178

  
179
                                  <div class="filters marginBottom20">
180
                                      <div class="links form-group form-inline">
181
                                          <span>Filter by community:</span>
182
                                          <select class="uk-select uk-width-medium" (change)="filterByCommunity($event)">
183
                                              <!--option value="">-- none selected --</option-->
184
                                              <option *ngFor="let community of communities" value="{{community.pid}}">{{community.name}}</option>
185
                                          </select>
186
                                      </div>
187
                                  </div>
188
                                  <table class="uk-table uk-table-striped">
189
                                    <thead>
190
                                        <tr>
191
                                            <th><input id="allPageCheckbox" type="checkbox" (change)="toggleCheckBoxes($event)"></th>
192
                                            <th>Name</th>
193
                                            <th>State</th>
194
                                            <th *ngIf="!pagesType">Type</th>
195
                                            <th>Related Entities</th>
196
                                            <th>Route</th>
197
                                            <th>Actions</th>
198
                                            <th>Page Help Contents</th>
199
                                            <th *ngIf="pageWithDivIds && pageWithDivIds.length > 0">Class Help Contents</th>
200
                                        </tr>
201
                                    </thead>
202
                                    <tbody >
203
                                        <tr *ngFor="let check of checkboxes; let i=index">
204
                                            <td><input id="{{check.page._id}}" class="checkBox" type="checkbox"
205
                                                                                name="pagescb[]" value="{{check.page._id}}" [(ngModel)]="check.checked">
206
                                            </td>
207
                                            <td>
208
                                                <div class="name" href="#">{{check.page.name}}</div>
209
                                            </td>
210
                                            <td>
211
                                              <div *ngIf="check.page.isEnabled" class="activated" >
212
                                                  <input (click)="togglePages(false,[check.page._id])" class="deactivate" src="imgs/check-icon.png" title="Disable" width="20" type="image" height="20">
213
                                              </div>
214
                                              <div *ngIf="!check.page.isEnabled" class="deactivated" >
215
                                                  <input (click)="togglePages(true,[check.page._id])" class="deactivate" src="imgs/x-icon.png" title="Enable" width="20" type="image" height="20">
216
                                              </div>
217
                                            </td>
218
                                            <td *ngIf="!pagesType">
219
                                                <div class="type" href="#">{{check.page.type}}</div>
220
                                            </td>
221
                                            <td>
222
                                                <div class="entities" href="#">
223
                                                  <span *ngFor="let entity of check.page.entities let i=index">{{entity.name}}<span *ngIf="i<(check.page.entities.length-1)">, </span></span>
224
                                                </div>
225
                                            </td>
226
                                            <td>
227
                                                <div class="route" href="#">{{check.page.route}}</div>
228
                                            </td>
229

  
230
                                            <td>
231
                                                <div class="actions" href="#">
232
                                                    <input title="Edit" src="imgs/icn_edit.png" class="edit" type="image" (click)="editPage(i)">
233
                                                    <input title="Delete" src="imgs/icn_trash.png" class="delete" type="image" (click)="confirmDeletePage(check.page._id)">
234
                                                </div>
235
                                            </td>
236
                                            <td>
237
                                              <a class="helpContents" [queryParams]="{community: selectedCommunityPid, page: check.page._id}" routerLink="/pageContents">add page contents</a>
238
                                            </td>
239
                                            <td *ngIf="pageWithDivIds && pageWithDivIds.length > 0" class="uk-text-center">
240
                                              <a *ngIf="pageWithDivIds.includes(check.page._id)" class="classHelpContents" [queryParams]="{community: selectedCommunityPid, page: check.page._id}" routerLink="/classContents">add class contents</a>
241
                                              <span *ngIf="!pageWithDivIds.includes(check.page._id)">-</span>
242
                                            </td>
243
                                        </tr>
244
                                    </tbody>
245
                                </table>
246

  
247
                                    <div *ngIf="checkboxes.length==0" class="col-md-12">
248
                                        <div class="uk-alert-warning" uk-alert>No pages found</div>
249
                                    </div>
250
                                </div>
251
                            </div>
252
                        </div>
253
                    </div>
254
                </div>
255
            </div>
256
        </div>
257
</div>
258
<modal-form #saveModal [saveText]="'Save'" [titleText]="'Add a new Page'" [formGroup]="formGroup" [type]="'page'"
259
            [isModalShown]="isModalShown" (emmitObject)="pageSavedSuccessfully($event)" (emmitError)="handleError($event)">
260
    <page-form [group]="formGroup"></page-form>
261
</modal-form>
262

  
263
<modal-form #updateModal [saveText]="'Update'" [titleText]="'Update Page'" [formGroup]="formGroup" [type]="'page'"
264
            [isModalShown]="isModalShown" (emmitObject)="pageUpdatedSuccessfully($event)" (emmitError)="handleError($event)">
265
    <page-form [group]="formGroup"></page-form>
266
</modal-form>
267

  
268
<delete-confirmation-dialog #deleteConfirmationModal [isModalShown]="isModalShown" (emmitObject)="confirmedDeletePages($event)">
269
    Are you sure you want to delete the selected page(s)?
270
</delete-confirmation-dialog>
modules/uoa-admin-portal/trunk/app/pages/helpcontent/page-form.component.ts
1
/**
2
 * Created by stefania on 7/13/17.
3
 */
4
import {Component, OnInit, Input} from '@angular/core';
5
import {FormGroup, FormArray, FormBuilder, Validators} from "@angular/forms";
6
import {Entity} from '../../domain/entity';
7
import { HelpContentService } from "../../services/help-content.service";
8

  
9
@Component({
10
    selector: 'page-form',
11
    templateUrl: './page-form.component.html',
12
})
13

  
14
export class PageFormComponent implements OnInit{
15

  
16
    @Input('group')
17
    myForm: FormGroup;
18
    @Input('type')
19
    public type: string;
20

  
21
    public errorMessage: string;
22

  
23
    public allEntities: Map<Entity, boolean> = new Map<Entity, boolean>();
24
    private gotEntities: boolean = false;
25

  
26
    constructor(public _fb: FormBuilder, private _helpContentService: HelpContentService){}
27

  
28
    ngOnInit(): void {}
29

  
30
    public toggle() {
31
      this.myForm.value.isCollapsed = !this.myForm.value.isCollapsed;
32

  
33
      if(!this.myForm.value.isCollapsed) {
34
        let includedEntities: Set<String> = new Set<String>();
35
        for(let entityName of this.myForm.value.entities) {
36
          includedEntities.add(entityName._id);
37
        }
38

  
39
        let allEntities = this.allEntities;
40

  
41
        let self = this;
42
        allEntities.forEach(function (status, entity, map) {
43
          if(includedEntities.has(entity._id)) {
44
            self.allEntities.set(entity, true);
45
          } else {
46
            self.allEntities.set(entity, false);
47
          }
48
        });
49

  
50

  
51
        if(!this.gotEntities) {
52
          this.gotEntities = true;
53
          this.getEntities(includedEntities);
54
        }
55
      }
56
    }
57

  
58
    public getEntities(includedEntities: Set<String>) {
59
      let self = this;
60
      this._helpContentService.getEntities().subscribe(
61
        entities => {
62
            for(let entity of entities) {
63
              if(includedEntities.has(entity._id)) {
64
                self.allEntities.set(entity, true);
65
              } else {
66
                self.allEntities.set(entity, false);
67
              }
68
            }
69
      },
70
      error => this.handleError('System error retrieving community entities', error));
71
    }
72

  
73
    public getKeys( map) {
74
      return Array.from(map.keys());
75
    }
76

  
77
    public get form() {
78
        return this._fb.group({
79
            route : ['', Validators.required],
80
            name : ['', Validators.required],
81
            isEnabled: '',
82
            type: ['', Validators.required],
83
            entities: this._fb.array([]),
84
            _id : '',
85
            isCollapsed: [true]
86
        });
87
    }
88

  
89
    public reset() {
90
        this.myForm.patchValue({
91
            route : '',
92
            name : '',
93
            type: '',
94
            isEnabled: '',
95
            //entities: this._fb.array([]),
96
            _id : '',
97
            isCollapsed: [true]
98
        });
99

  
100
        this.setEntities([]);
101
    }
102

  
103
    public get entities(): FormArray {
104
      return this.myForm.get('entities') as FormArray;
105
    };
106

  
107
    setEntities(entities: Entity[]) {
108
      const entityFGs = entities.map(entity => this._fb.group(entity));
109
      const entityFormArray = this._fb.array(entityFGs);
110
      this.myForm.setControl('entities', entityFormArray);
111
    }
112

  
113
    addEntity() {
114
      this.myForm.value.entities.push(this._fb.group(new Entity()));
115
    }
116

  
117
    public toggleEntity(status : boolean, id : string, entity: Entity) {
118
      let index: number = -1;
119
      for(let i=0; i<this.myForm.get('entities').value.length; i++) {
120
        if(this.myForm.get('entities').value[i]._id == entity._id) {
121
          index = i;
122
          break;
123
        }
124
      }
125
      console.info("status: "+status + "   index: "+index);
126

  
127
      this.allEntities.set(entity, status);
128

  
129
      if(status && index<0) {
130
        this.myForm.value.entities.push(entity);
131
        console.info("push :   "+this.myForm.value.entities.length);
132
      } else  if(!status){
133
        if(index >= 0) {
134
          this.myForm.value.entities.splice(index, 1);
135
          console.info("delete :   "+this.myForm.value.entities.length);
136
        }
137
      }
138
/*
139
      this._helpContentService.toggleEntityOfPage(this.myForm.value._id,id,status).subscribe(
140
          () => {
141

  
142
          },
143
          error => this.handleError('System error changing the status of the enity of page', error)
144
      );
145
*/
146
    }
147

  
148
    handleError(message: string, error) {
149
        if(error == null) {
150
            this.reset();
151
        }
152
        this.errorMessage = message + ' (Server responded: ' + error + ')';
153
    }
154
}
modules/uoa-admin-portal/trunk/app/pages/helpcontent/entity-form.component.ts
1
import {Component, OnInit, Input} from '@angular/core';
2
import {FormGroup, FormBuilder, Validators} from "@angular/forms";
3

  
4

  
5
@Component({
6
    selector: 'entity-form',
7
    templateUrl: './entity-form.component.html',
8
})
9

  
10
export class EntityFormComponent implements OnInit{
11

  
12
    @Input('group')
13
    myForm: FormGroup;
14

  
15
    constructor(private _fb: FormBuilder){}
16

  
17
    ngOnInit(): void {
18
    }
19

  
20
    public get form() {
21
        return this._fb.group({
22
            pid: ['', Validators.required],
23
            name : ['', Validators.required],
24
            isEnabled: '',
25
            _id : ''
26
        });
27
    }
28

  
29
    public reset() {
30
        this.myForm.patchValue({
31
            pid: '',
32
            name : '',
33
            isEnabled: '',
34
            _id : ''
35
        });
36
    }
37

  
38
}
modules/uoa-admin-portal/trunk/app/pages/helpcontent/entities.component.ts
1
import { Component, ViewChild, OnInit } from '@angular/core';
2
import { HelpContentService } from "../../services/help-content.service";
3
import { FormGroup } from "@angular/forms";
4
import { ModalFormComponent } from "../modal-form.component";
5
import { DeleteConfirmationDialogComponent } from "../delete-confirmation-dialog.component";
6
import { EntityFormComponent } from "./entity-form.component";
7
import { CheckEntity, Entity } from "../../domain/entity";
8
import { Community } from "../../domain/community";
9

  
10
@Component({
11
    selector: 'entities',
12
    templateUrl: './entities.component.html',
13
})
14

  
15
export class EntitiesComponent implements OnInit {
16

  
17
    // @ViewChild(ModalFormComponent)
18
    @ViewChild('saveModal')
19
    public modal:ModalFormComponent;
20

  
21
    @ViewChild('updateModal')
22
    public updateModal:ModalFormComponent;
23

  
24
    @ViewChild('deleteConfirmationModal')
25
    public deleteConfirmationModal : DeleteConfirmationDialogComponent;
26

  
27
    @ViewChild(EntityFormComponent)
28
    public formComponent : EntityFormComponent;
29

  
30
    public checkboxes : CheckEntity[] = [];
31

  
32
    public entities : Entity[] = [];
33

  
34
    public errorMessage: string;
35

  
36
    public formGroup : FormGroup;
37

  
38
    private searchText : RegExp = new RegExp('');
39

  
40
    public communities: Community[] = [];
41

  
42
    public selectedCommunityPid: string;
43
    @ViewChild('okModal')
44
    public okModal:ModalFormComponent;
45
public toggleIds: string[];
46
public toggleStatus: boolean;
47

  
48
    ngOnInit() {
49
        this.getCommunities();
50

  
51
        this.formGroup = this.formComponent.form;
52
    }
53

  
54
    constructor(private _helpContentService: HelpContentService) {}
55

  
56
    getCommunities() {
57
        let self = this;
58
        this._helpContentService.getCommunities().subscribe(
59
            communities => {
60
                self.communities = communities;
61
                self.selectedCommunityPid = self.communities[0].pid;
62
                self.getEntities(self.selectedCommunityPid);
63
        },
64
        error => this.handleError('System error retrieving communities', error));
65
    }
66

  
67
    getEntities(community_pid: string) {
68
        let self = this;
69
        this._helpContentService.getCommunityEntities(community_pid).subscribe(
70
            entities => {
71
                self.entities = entities;
72
                self.checkboxes = [];
73

  
74
                entities.forEach(_ => {
75
                    self.checkboxes.push(<CheckEntity>{entity : _, checked : false});
76
                });
77
        },
78
        error => this.handleError('System error retrieving entities', error));
79
    }
80

  
81
    public showModal():void {
82
        this.modal.showModal();
83
    }
84

  
85
    public toggleCheckBoxes(event) {
86
        this.checkboxes.forEach(_ => _.checked = event.target.checked);
87
    }
88

  
89
    public applyCheck(flag : boolean) {
90
      console.info("applyCheck "+flag);
91
        this.checkboxes.forEach(_ => _.checked = flag);
92
    }
93

  
94
    public getSelectedEntities() : string[] {
95
        return this.checkboxes.filter(entity => entity.checked == true).map(checkedEntity => checkedEntity.entity).map(res => res._id);
96
    }
97

  
98
    private deleteEntitiesFromArray(ids : string[]) : void {
99
        for(let id of ids) {
100
            let i = this.checkboxes.findIndex(_ => _.entity._id == id);
101
            this.checkboxes.splice(i, 1);
102
        }
103
    }
104

  
105
    public confirmDeleteEntity(id : string) {
106
        this.deleteConfirmationModal.ids = [id];
107
        this.deleteConfirmationModal.showModal();
108
    }
109

  
110
    public confirmDeleteSelectedEntities() {
111
        this.deleteConfirmationModal.ids = this.getSelectedEntities();
112
        this.deleteConfirmationModal.showModal();
113
    }
114

  
115
    public confirmedDeleteEntities(ids : string[]) {
116
        this._helpContentService.deleteEntities(ids).subscribe(
117
            _ => this.deleteEntitiesFromArray(ids),
118
            error => this.handleError('System error deleting the selected entities', error)
119
        );
120
    }
121

  
122
    public editEntity(i : number) {
123
        let entity : Entity = this.checkboxes[i].entity;
124
        this.formGroup.patchValue(entity);
125
        this.updateModal.showModal();
126
    }
127

  
128
    public entitySavedSuccessfully(entity: Entity) {
129
        this.checkboxes.push(<CheckEntity>{entity : entity, checked : false});
130
        this.applyCheck(false);
131
    }
132

  
133
    public entityUpdatedSuccessfully(entity : Entity) {
134
        this.checkboxes.find(checkItem => checkItem.entity._id==entity._id).entity = entity;
135
        this.applyCheck(false);
136
    }
137

  
138
    public filterBySearch(text : string) {
139
        this.searchText = new RegExp(text,'i');
140
        this.applyFilter();
141
    }
142

  
143
    public applyFilter() {
144
        this.checkboxes = [];
145
        this.entities.filter(item => this.filterEntities(item)).forEach(
146
            _ => this.checkboxes.push(<CheckEntity>{entity: _, checked: false})
147
        );
148
    }
149

  
150
    public filterEntities(entity : Entity) : boolean {
151
        let textFlag = this.searchText.toString() == '' || (entity.name).match(this.searchText) != null;
152
        return textFlag;
153
    }
154

  
155
    handleError(message: string, error) {
156
        if(error == null) {
157
            this.formComponent.reset();
158
        }
159
        this.errorMessage = message + ' (Server responded: ' + error + ')';
160
    }
161

  
162

  
163

  
164
    public filterByCommunity(event: any) {
165
        this.selectedCommunityPid = event.target.value;
166
        this.applyCommunityFilter(this.selectedCommunityPid);
167
    }
168

  
169
    public applyCommunityFilter(community_pid: string) {
170
        this.getEntities(community_pid);
171
    }
172

  
173
    public toggleEntities(status : boolean, ids : string[]) {
174
        this.okModal.showModal();
175
        this.toggleIds = ids;
176
        this.toggleStatus = status;
177
    }
178

  
179
    public continueToggling(event: any) {
180
      this._helpContentService.toggleEntities(this.selectedCommunityPid,this.toggleIds,this.toggleStatus).subscribe(
181
          () => {
182
            for(let id of this.toggleIds) {
183
              let i = this.checkboxes.findIndex(_ => _.entity._id == id);
184
              this.checkboxes[i].entity.isEnabled=this.toggleStatus;
185
            }
186
            this.applyCheck(false);
187
          },
188
          error => this.handleError('System error changing the status of the selected entity(-ies)', error)
189
      );
190
    }
191

  
192
  }
modules/uoa-admin-portal/trunk/app/pages/entity/entity-form.component.html
1
<form [formGroup]="myForm">
2
    <div class="form-group" [ngClass]="{'has-error':!myForm.controls.name.valid && myForm.controls.name.dirty}">
3
        <label for="entityNameTag">Entity Name</label>
4
        <input type="text" class="uk-input uk-width-medium" formControlName="name" id="entityNameTag" placeholder="Entity Name">
5
    </div>
6
    <div class="form-group" [ngClass]="{'has-error':!myForm.controls.pid.valid && myForm.controls.pid.dirty}">
7
        <label for="entityPidTag">Entity persistent id for portal</label>
8
        <input type="text" class="uk-input uk-width-medium" formControlName="pid" id="entityPidTag" placeholder="Entity Pid">
9
    </div>
10

  
11
<!--
12
    <div ngModelGroup="phoneNumbers">
13
      <h3>Phone numbers</h3>
14
      <div *ngFor="let phoneId of phoneNumberIds; let i=index;">
15
        <label>Phone number {{i + 1}}</label>
16
        <input type="text" name="phoneNumber[{{phoneId}}]" #phoneNumber="ngModel" ngModel/>
17
        <button type="button" (click)="remove(i); myForm.control.markAsTouched()">remove</button>
18
      </div>
19
      <button type="button" (click)="add(); myForm.control.markAsTouched()">Add phone number</button>
20
    </div>
21
-->
22

  
23
<!-- <div class="form-group" [ngClass]="{'has-error':!myForm.controls.name.valid && myForm.controls.entities.dirty}">
24
  <div *ngFor="let entity of entities; let i=index;">
25
    <label>Entity {{i + 1}}</label>
26
    <input type="text" name="entities[{{entity}}]" class="form-control" formControlName="entity"/>
27
  </div>
28
</div> -->
29

  
30

  
31
    <input type="hidden" formControlName="_id">
32
</form>
33
<!--<pre>-->
34
<!--{{myForm.value | json}}-->
35
<!--</pre>-->
modules/uoa-admin-portal/trunk/app/pages/entity/entity-form.component.ts
1
import {Component, OnInit, Input} from '@angular/core';
2
import {FormGroup, FormBuilder, Validators} from "@angular/forms";
3

  
4

  
5
@Component({
6
    selector: 'entity-form',
7
    templateUrl: './entity-form.component.html',
8
})
9

  
10
export class EntityFormComponent implements OnInit{
11

  
12
    @Input('group')
13
    myForm: FormGroup;
14

  
15
    constructor(private _fb: FormBuilder){}
16

  
17
    ngOnInit(): void {
18
    }
19

  
20
    public get form() {
21
        return this._fb.group({
22
            pid: ['', Validators.required],
23
            name : ['', Validators.required],
24
            isEnabled: '',
25
            _id : ''
26
        });
27
    }
28

  
29
    public reset() {
30
        this.myForm.patchValue({
31
            pid: '',
32
            name : '',
33
            isEnabled: '',
34
            _id : ''
35
        });
36
    }
37

  
38
}
modules/uoa-admin-portal/trunk/app/pages/entity/entities.component.html
1
<div id="entities" class="uk-container">
2

  
3
        <div class="menubar ">
4

  
5
            <div class="entity-title uk-article-title  ">Entities</div>
6
            <form target="BSFormPanel_Admin_1" class="search">
7
                <input #inputstring (keyup.enter)="filterBySearch(inputstring.value)" placeholder="Entity name..." type="text" class="uk-input uk-width-medium"/>
8
                <button class="uk-button" type="submit">Search</button>
9
            </form>
10
            <a (click)="showModal()" class="uk-button uk-button-primary uk-float-right"><i></i> New Entity </a>
11
        </div>
12

  
13
        <div class="content-wrapper" id="contentWrapper">
14
            <div>
15
                <div class="contentPanel">
16
                    <div class="uk-alert-danger" uk-alert style="display: none;" aria-hidden="true">
17
                        <span></span><span></span><span></span></div>
18
                    <div class="uk-alert-success" uk-alert style="display: none;" aria-hidden="true">
19
                        <span></span><span></span><span></span></div>
20
                    <div class="uk-alert" uk-alert style="display: none;" aria-hidden="true"><span></span><span></span><span></span></div>
21

  
22
                    <div class="page-controls">
23
                        <div class="  filters ">
24
                            <div class="show-options uk-float-right">
25
                              <button class="uk-button" type="button"> Bulk Actions</button>
26
                              <div uk-dropdown="mode: click">
27
                                <ul class="uk-nav uk-dropdown-nav">
28
                                    <li><a (click)="toggleEntities(true, getSelectedEntities())"><i></i> Activate </a></li>
29
                                    <li><a (click)="toggleEntities(false, getSelectedEntities())"><i></i> Deactivate </a></li>
30
                                    <li><a (click)="confirmDeleteSelectedEntities()"><i></i> Delete </a></li>
31
                                </ul>
32
                              </div>
33
                                <!--div class="btn-group"><a href="javascript:;" class="btn dropdown-toggle"
34
                                                          data-toggle="dropdown"><i></i> Bulk Actions <span
35
                                        class="caret"></span></a>
36
                                    <ul class="dropdown-menu">
37
                                        <li><a (click)="confirmDeleteSelectedEntities()"><i></i> Delete </a></li>
38
                                    </ul>
39
                                </div-->
40
                            </div>
41
                        </div>
42
                    </div>
43

  
44
                    <div>
45
                        <div class="gwt-HTML">
46
                            <div class="row users-list">
47
                                <div class="col-md-12">
48

  
49
                                  <div class="filters marginBottom20">
50
                                      <div class="links form-group form-inline">
51
                                          <span>Filter by community:</span>
52
                                          <select class="uk-select uk-width-medium" (change)="filterByCommunity($event)">
53
                                              <!--option value="">-- none selected --</option-->
54
                                              <option *ngFor="let community of communities" value="{{community.pid}}">{{community.name}}</option>
55
                                          </select>
56
                                      </div>
57
                                  </div>
58
                                  <table class="uk-table uk-table-striped">
59
                                    <thead>
60
                                        <tr>
61
                                            <th><input id="allEntityCheckbox" type="checkbox" (change)="toggleCheckBoxes($event)"></th>
62
                                            <th>Name</th>
63
                                            <th>State</th>
64
                                            <th>Actions</th>
65
                                        </tr>
66
                                    </thead>
67
                                    <tbody >
68
                                        <tr *ngFor="let check of checkboxes; let i=index">
69
                                            <td><input id="{{check.entity._id}}" class="checkBox" type="checkbox"
70
                                                                                name="entitiescb[]" value="{{check.entity._id}}" [(ngModel)]="check.checked">
71
                                            </td>
72
                                            <td>
73
                                                <div class="name" href="#">{{check.entity.name}}</div>
74
                                            </td>
75
                                            <td>
76
                                              <div *ngIf="check.entity.isEnabled" class="activated" >
77
                                                  <input (click)="toggleEntities(false,[check.entity._id])" class="deactivate" src="imgs/check-icon.png" title="Disable" width="20" type="image" height="20">
78
                                              </div>
79
                                              <div *ngIf="!check.entity.isEnabled" class="deactivated" >
80
                                                  <input (click)="toggleEntities(true,[check.entity._id])" class="deactivate" src="imgs/x-icon.png" title="Enable" width="20" type="image" height="20">
81
                                              </div>
82
                                            </td>
83
                                            <td>
84
                                                <div class="actions" href="#">
85
                                                    <input title="Edit" src="imgs/icn_edit.png" class="edit" type="image" (click)="editEntity(i)">
86
                                                    <input title="Delete" src="imgs/icn_trash.png" class="delete" type="image" (click)="confirmDeleteEntity(check.entity._id)">
87
                                                </div>
88
                                            </td>
89
                                        </tr>
90
                                    </tbody>
91
                                </table>
92

  
93
                                    <div *ngIf="checkboxes.length==0" class="col-md-12">
94
                                        <div class="uk-alert-warning" uk-alert>No entities found</div>
95
                                    </div>
96
                                </div>
97
                            </div>
98
                        </div>
99
                    </div>
100
                </div>
101
            </div>
102
        </div>
103
</div>
104
<modal-form #saveModal [saveText]="'Save'" [titleText]="'Add a new Entity'" [formGroup]="formGroup" [type]="'entity'"
105
            [isModalShown]="isModalShown" (emmitObject)="entitySavedSuccessfully($event)" (emmitError)="handleError($event)">
106
    <entity-form [group]="formGroup"></entity-form>
107
</modal-form>
108

  
109
<modal-form #updateModal [saveText]="'Update'" [titleText]="'Update Entity'" [formGroup]="formGroup" [type]="'entity'"
110
            [isModalShown]="isModalShown" (emmitObject)="entityUpdatedSuccessfully($event)" (emmitError)="handleError($event)">
111
    <entity-form [group]="formGroup"></entity-form>
112
</modal-form>
113
<modal-form #okModal [saveText]="'OK'" [titleText]="'Warning'" [type]="'none'"
114
            [isModalShown]="isModalShown" (emmitObject)="continueToggling($event)" (emmitError)="handleError($event)">
115
            This action will affect all search pages related to this entity!
116
            Pages' status will change to entity's status!
117
            Do you want to continue?
118
<modal-form>
119
<delete-confirmation-dialog #deleteConfirmationModal [isModalShown]="isModalShown" (emmitObject)="confirmedDeleteEntities($event)">
120
    Are you sure you want to delete the selected entity(-ies)?
121
</delete-confirmation-dialog>
modules/uoa-admin-portal/trunk/app/pages/entity/entities.component.ts
1
import { Component, ViewChild, OnInit } from '@angular/core';
2
import { HelpContentService } from "../../services/help-content.service";
3
import { FormGroup } from "@angular/forms";
4
import { ModalFormComponent } from "../modal-form.component";
5
import { DeleteConfirmationDialogComponent } from "../delete-confirmation-dialog.component";
6
import { EntityFormComponent } from "./entity-form.component";
7
import { CheckEntity, Entity } from "../../domain/entity";
8
import { Community } from "../../domain/community";
9

  
10
@Component({
11
    selector: 'entities',
12
    templateUrl: './entities.component.html',
13
})
14

  
15
export class EntitiesComponent implements OnInit {
16

  
17
    // @ViewChild(ModalFormComponent)
18
    @ViewChild('saveModal')
19
    public modal:ModalFormComponent;
20

  
21
    @ViewChild('updateModal')
22
    public updateModal:ModalFormComponent;
23

  
24
    @ViewChild('deleteConfirmationModal')
25
    public deleteConfirmationModal : DeleteConfirmationDialogComponent;
26

  
27
    @ViewChild(EntityFormComponent)
28
    public formComponent : EntityFormComponent;
29

  
30
    public checkboxes : CheckEntity[] = [];
31

  
32
    public entities : Entity[] = [];
33

  
34
    public errorMessage: string;
35

  
36
    public formGroup : FormGroup;
37

  
38
    private searchText : RegExp = new RegExp('');
39

  
40
    public communities: Community[] = [];
41

  
42
    public selectedCommunityPid: string;
43
    @ViewChild('okModal')
44
    public okModal:ModalFormComponent;
45
public toggleIds: string[];
46
public toggleStatus: boolean;
47

  
48
    ngOnInit() {
49
        this.getCommunities();
50

  
51
        this.formGroup = this.formComponent.form;
52
    }
53

  
54
    constructor(private _helpContentService: HelpContentService) {}
55

  
56
    getCommunities() {
57
        let self = this;
58
        this._helpContentService.getCommunities().subscribe(
59
            communities => {
60
                self.communities = communities;
61
                self.selectedCommunityPid = self.communities[0].pid;
62
                self.getEntities(self.selectedCommunityPid);
63
        },
64
        error => this.handleError('System error retrieving communities', error));
65
    }
66

  
67
    getEntities(community_pid: string) {
68
        let self = this;
69
        this._helpContentService.getCommunityEntities(community_pid).subscribe(
70
            entities => {
71
                self.entities = entities;
72
                self.checkboxes = [];
73

  
74
                entities.forEach(_ => {
75
                    self.checkboxes.push(<CheckEntity>{entity : _, checked : false});
76
                });
77
        },
78
        error => this.handleError('System error retrieving entities', error));
79
    }
80

  
81
    public showModal():void {
82
        this.modal.showModal();
83
    }
84

  
85
    public toggleCheckBoxes(event) {
86
        this.checkboxes.forEach(_ => _.checked = event.target.checked);
87
    }
88

  
89
    public applyCheck(flag : boolean) {
90
      console.info("applyCheck "+flag);
91
        this.checkboxes.forEach(_ => _.checked = flag);
92
    }
93

  
94
    public getSelectedEntities() : string[] {
95
        return this.checkboxes.filter(entity => entity.checked == true).map(checkedEntity => checkedEntity.entity).map(res => res._id);
96
    }
97

  
98
    private deleteEntitiesFromArray(ids : string[]) : void {
99
        for(let id of ids) {
100
            let i = this.checkboxes.findIndex(_ => _.entity._id == id);
101
            this.checkboxes.splice(i, 1);
102
        }
103
    }
104

  
105
    public confirmDeleteEntity(id : string) {
106
        this.deleteConfirmationModal.ids = [id];
107
        this.deleteConfirmationModal.showModal();
108
    }
109

  
110
    public confirmDeleteSelectedEntities() {
111
        this.deleteConfirmationModal.ids = this.getSelectedEntities();
112
        this.deleteConfirmationModal.showModal();
113
    }
114

  
115
    public confirmedDeleteEntities(ids : string[]) {
116
        this._helpContentService.deleteEntities(ids).subscribe(
117
            _ => this.deleteEntitiesFromArray(ids),
118
            error => this.handleError('System error deleting the selected entities', error)
119
        );
120
    }
121

  
122
    public editEntity(i : number) {
123
        let entity : Entity = this.checkboxes[i].entity;
124
        this.formGroup.patchValue(entity);
125
        this.updateModal.showModal();
126
    }
127

  
128
    public entitySavedSuccessfully(entity: Entity) {
129
        this.checkboxes.push(<CheckEntity>{entity : entity, checked : false});
130
        this.applyCheck(false);
131
    }
132

  
133
    public entityUpdatedSuccessfully(entity : Entity) {
134
        this.checkboxes.find(checkItem => checkItem.entity._id==entity._id).entity = entity;
135
        this.applyCheck(false);
136
    }
137

  
138
    public filterBySearch(text : string) {
139
        this.searchText = new RegExp(text,'i');
140
        this.applyFilter();
141
    }
142

  
143
    public applyFilter() {
144
        this.checkboxes = [];
145
        this.entities.filter(item => this.filterEntities(item)).forEach(
146
            _ => this.checkboxes.push(<CheckEntity>{entity: _, checked: false})
147
        );
148
    }
149

  
150
    public filterEntities(entity : Entity) : boolean {
151
        let textFlag = this.searchText.toString() == '' || (entity.name).match(this.searchText) != null;
152
        return textFlag;
153
    }
154

  
155
    handleError(message: string, error) {
156
        if(error == null) {
157
            this.formComponent.reset();
158
        }
159
        this.errorMessage = message + ' (Server responded: ' + error + ')';
160
    }
161

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff