Project

General

Profile

« Previous | Next » 

Revision 59753

[Monitor Dashboard | Trunk]: Disable alias and indeces when user is not portal admin

View differences:

modules/uoa-monitor-portal/trunk/monitor_dashboard/src/app/general/edit-stakeholder/edit-stakeholder.component.ts
8 8
import {properties} from "../../../environments/environment";
9 9
import {StakeholderService} from "../../openaireLibrary/monitor/services/stakeholder.service";
10 10
import {UtilitiesService} from "../../openaireLibrary/services/utilities.service";
11
import {User} from "../../openaireLibrary/login/utils/helper.class";
11
import {Session, User} from "../../openaireLibrary/login/utils/helper.class";
12 12
import {UserManagementService} from "../../openaireLibrary/services/user-management.service";
13 13

  
14 14
declare var UIkit;
......
27 27
        <div dashboard-input class="uk-width-1-2@m" [formInput]="stakeholderFb.get('alias')"
28 28
             hint="Set an URL alias for your profile."
29 29
             label="URL Alias" placeholder="Write an alias..."></div>
30
        <!-- TODO Add Portal Administrator condition -->
31 30
        <div dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('index_id')"
32 31
             label="Index ID" placeholder="Write index ID.">
33 32
        </div>
......
47 46
          <div *ngIf="!stakeholderFb.get('isUpload').value" class="uk-width-2-5@l uk-width-1-1">
48 47
            <div class="uk-grid uk-flex uk-flex-middle" uk-grid>
49 48
              <div class="uk-width-3-4@l uk-width-1-1 uk-flex uk-flex-center">
50
                <button class="uk-button uk-button-secondary uk-flex uk-flex-middle uk-flex-wrap" (click)="file.click()">
49
                <button class="uk-button uk-button-secondary uk-flex uk-flex-middle uk-flex-wrap"
50
                        (click)="file.click()">
51 51
                  <icon name="cloud_upload" [flex]="true"></icon>
52 52
                  <span class="uk-margin-small-left">Upload a file</span>
53 53
                </button>
......
80 80
             [options]="stakeholderUtils.statuses" type="select">
81 81
        </div>
82 82
        <div dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('type')"
83
             [placeholder]="'Select a type'" hint="Select the type of your profile" 
84
             label="Type" [options]="stakeholderUtils.getTypesByUserRoles(user, stakeholder.alias)" type="select">
83
             [placeholder]="'Select a type'" hint="Select the type of your profile"
84
             label="Type" [options]="types" type="select">
85 85
        </div>
86
        <ng-container *ngIf="!stakeholderFb.get('isDefault').value && isNew && stakeholderFb.get('type').valid && defaultStakeholdersOptions">
86
        <ng-container
87
            *ngIf="!stakeholderFb.get('isDefault').value && isNew && stakeholderFb.get('type').valid && defaultStakeholdersOptions">
87 88
          <div [placeholder]="'Select a template'"
88 89
               hint="Select a template for your profile"
89 90
               dashboard-input class="uk-width-1-3@m" [formInput]="stakeholderFb.get('defaultId')"
......
108 109
  public stakeholder: Stakeholder;
109 110
  public isDefault: boolean;
110 111
  public isNew: boolean;
112
  public types: Option[];
111 113
  public properties: EnvProperties = properties;
112 114
  private subscriptions: any[] = [];
113 115
  /**
......
119 121
  public deleteCurrentPhoto: boolean = false;
120 122
  private maxsize: number = 200 * 1024;
121 123
  user: User;
124
  
122 125
  constructor(private fb: FormBuilder,
123 126
              private stakeholderService: StakeholderService,
124 127
              private utilsService: UtilitiesService, private userManagementService: UserManagementService,) {
......
137 140
    this.isDefault = isDefault;
138 141
    this.isNew = isNew;
139 142
    this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
140
      this.user = user;
141
    }));
142
    this.stakeholderFb = this.fb.group({
143
      _id: this.fb.control(this.stakeholder._id),
144
      defaultId: this.fb.control(this.stakeholder.defaultId),
145
      name: this.fb.control(this.stakeholder.name, Validators.required),
146
      description: this.fb.control(this.stakeholder.description),
147
      index_name: this.fb.control(this.stakeholder.index_name, Validators.required),
148
      index_id: this.fb.control(this.stakeholder.index_id, Validators.required),
149
      index_shortName: this.fb.control(this.stakeholder.index_shortName, Validators.required),
150
      creationDate: this.fb.control(this.stakeholder.creationDate),
151
      alias: this.fb.control(this.stakeholder.alias,
152
        [
153
          Validators.required,
154
          this.stakeholderUtils.aliasValidator(
155
            (this.isDefault) ?
156
              this.defaultStakeholders.filter(stakeholder => stakeholder.alias !== this.stakeholder.alias) :
157
              this.stakeholders.filter(stakeholder => stakeholder.alias !== this.stakeholder.alias)
158
          )]
159
      ),
160
      isDefault: this.fb.control((this.isDefault)),
161
      visibility: this.fb.control(this.stakeholder.visibility, Validators.required),
162
      type: this.fb.control(this.stakeholder.type, Validators.required),
163
      topics: this.fb.control(this.stakeholder.topics),
164
      managers: this.fb.control(this.stakeholder.managers),
165
      isUpload: this.fb.control(this.stakeholder.isUpload),
166
      logoUrl: this.fb.control(this.stakeholder.logoUrl),
167
    });
168
    this.initPhoto();
169
    if (!isDefault) {
170
      this.subscriptions.push(this.stakeholderFb.get('type').valueChanges.subscribe(value => {
171
        this.onTypeChange(value, defaultStakeholders);
172
      }));
173
      this.stakeholderFb.setControl('defaultId', this.fb.control(stakeholder.defaultId, Validators.required));
174
    }
175
    if(this.disableAlias) {
176
      setTimeout(() => {
177
        this.stakeholderFb.get('alias').disable();
178
      }, 0);
179
    }
180
    if (isNew) {
181
      setTimeout(() => {
182
        this.stakeholderFb.get('type').enable();
183
      }, 0);
184
    } else {
185
      setTimeout(() => {
186
        this.stakeholderFb.get('type').disable();
187
      }, 0);
188
    }
143
        this.user = user;
144
        this.types = this.stakeholderUtils.getTypesByUserRoles(this.user, this.stakeholder.alias);
145
        this.stakeholderFb = this.fb.group({
146
          _id: this.fb.control(this.stakeholder._id),
147
          defaultId: this.fb.control(this.stakeholder.defaultId),
148
          name: this.fb.control(this.stakeholder.name, Validators.required),
149
          description: this.fb.control(this.stakeholder.description),
150
          index_name: this.fb.control(this.stakeholder.index_name, Validators.required),
151
          index_id: this.fb.control(this.stakeholder.index_id, Validators.required),
152
          index_shortName: this.fb.control(this.stakeholder.index_shortName, Validators.required),
153
          creationDate: this.fb.control(this.stakeholder.creationDate),
154
          alias: this.fb.control(this.stakeholder.alias,
155
            [
156
              Validators.required,
157
              this.stakeholderUtils.aliasValidator(
158
                (this.isDefault) ?
159
                  this.defaultStakeholders.filter(stakeholder => stakeholder.alias !== this.stakeholder.alias) :
160
                  this.stakeholders.filter(stakeholder => stakeholder.alias !== this.stakeholder.alias)
161
              )]
162
          ),
163
          isDefault: this.fb.control((this.isDefault)),
164
          visibility: this.fb.control(this.stakeholder.visibility, Validators.required),
165
          type: this.fb.control(this.stakeholder.type, Validators.required),
166
          topics: this.fb.control(this.stakeholder.topics),
167
          managers: this.fb.control(this.stakeholder.managers),
168
          isUpload: this.fb.control(this.stakeholder.isUpload),
169
          logoUrl: this.fb.control(this.stakeholder.logoUrl),
170
        });
171
        this.initPhoto();
172
        if (!isDefault) {
173
          this.subscriptions.push(this.stakeholderFb.get('type').valueChanges.subscribe(value => {
174
            this.onTypeChange(value, defaultStakeholders);
175
          }));
176
          this.stakeholderFb.setControl('defaultId', this.fb.control(stakeholder.defaultId, Validators.required));
177
        }
178
        if (Session.isPortalAdministrator(this.user)) {
179
          if (this.disableAlias) {
180
            setTimeout(() => {
181
              this.stakeholderFb.get('alias').disable();
182
            }, 0);
183
          }
184
        } else {
185
          setTimeout(() => {
186
            this.stakeholderFb.get('alias').disable();
187
            this.stakeholderFb.get('index_id').disable();
188
            this.stakeholderFb.get('index_name').disable();
189
            this.stakeholderFb.get('index_shortName').disable();
190
          }, 0);
191
        }
192
        if (isNew) {
193
          setTimeout(() => {
194
            this.stakeholderFb.get('type').enable();
195
          }, 0);
196
        } else {
197
          setTimeout(() => {
198
            this.stakeholderFb.get('type').disable();
199
          }, 0);
200
        }
201
      }
202
    ));
189 203
  }
190 204
  
191 205
  public get disabled(): boolean {
......
241 255
    }
242 256
  }
243 257
  
244
  public saveStakeholder(callback: Function,  errorCallback: Function = null) {
258
  public saveStakeholder(callback: Function, errorCallback: Function = null) {
245 259
    if (this.isNew) {
246 260
      if (!this.stakeholderFb.value.isDefault) {
247 261
        let stakeholder = this.defaultStakeholders.find(value => value._id === this.stakeholderFb.value.defaultId);
......
251 265
      this.removePhoto();
252 266
      this.stakeholderService.buildStakeholder(this.properties.monitorServiceAPIURL,
253 267
        this.stakeholderFb.value).subscribe(stakeholder => {
254
        UIkit.notification(stakeholder.name+ '\'s has been successfully created', {
268
        UIkit.notification(stakeholder.name + '\'s has been successfully created', {
255 269
          status: 'success',
256 270
          timeout: 3000,
257 271
          pos: 'top-left'
......
263 277
          timeout: 3000,
264 278
          pos: 'top-left'
265 279
        });
266
        if(errorCallback) {
280
        if (errorCallback) {
267 281
          errorCallback(error)
268 282
        }
269 283
      });
270 284
    } else {
271 285
      this.stakeholderFb.get('type').enable();
272 286
      this.stakeholderFb.get('alias').enable();
287
      this.stakeholderFb.get('index_id').enable();
288
      this.stakeholderFb.get('index_name').enable();
289
      this.stakeholderFb.get('index_shortName').enable();
273 290
      this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.value).subscribe(stakeholder => {
274
        UIkit.notification(stakeholder.name+ '\'s has been successfully saved', {
291
        UIkit.notification(stakeholder.name + '\'s has been successfully saved', {
275 292
          status: 'success',
276 293
          timeout: 3000,
277 294
          pos: 'top-left'

Also available in: Unified diff