Project

General

Profile

« Previous | Next » 

Revision 53198

Added by Sofia Baltzi over 5 years ago

Add manage user notification form's functionality, services and userNotificationsRights class

View differences:

manage-user-notification.component.ts
1 1
import {Component, OnInit, Input} from '@angular/core';
2
import {FormBuilder} from '@angular/forms';
2
import {FormGroup, FormBuilder} from '@angular/forms';
3 3
import {ActivatedRoute, Router} from '@angular/router';
4
import {CommonModule} from "@angular/common";
4 5

  
5 6
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
6 7

  
7 8
import {Session} from '../../openaireLibrary/login/utils/helper.class';
8 9

  
10
import {ManageUserNotificationService} from './manage-user-notification.service';
11

  
12
import {UserNotificationsRights} from './userNotificationsRights';
13

  
9 14
@Component({
10 15
    selector: 'manage-user-notification',
11 16
    templateUrl: './manage-user-notification.component.html',
12 17
})
13 18

  
14

  
15 19
export class ManageUserNotificationComponent implements OnInit {
16 20

  
21
    @Input('group')
22
    myForm: FormGroup;
23

  
17 24
    public properties: EnvProperties = null;
18 25
    public communityId = null;
26
    public userNotifications = null;
27
    public userEmail = null;
19 28

  
20
    constructor (private route: ActivatedRoute, private _router: Router, public _fb: FormBuilder) {
29
    public successfulSaveMessage: string = '';
30
    public successfulResetMessage: string = '';
31

  
32
    public hasChanged: boolean = false;
33

  
34
    constructor (private route: ActivatedRoute, private _router: Router, public _fb: FormBuilder,
35
                 private _manageUserNotificationService: ManageUserNotificationService) {
21 36
    }
22 37

  
23 38
    ngOnInit() {
......
28 43
                    this.communityId = communityId['communityId'];
29 44
                    if (this.communityId != null && this.communityId != '') {
30 45
                        if (Session.getUser()) {
31
                            Session.getUserEmail();
46
                            this.userEmail = Session.getUserEmail();
32 47
                        }
48

  
49
                        this._manageUserNotificationService.getUserNotification("http://scoobydoo.di.uoa.gr:8080/uoa-admin-tools/community/" + this.communityId + "/notifications", this.userEmail).subscribe(
50
                            userNotifications => {
51
                                this.userNotifications = userNotifications;
52

  
53
                                if (this.userNotifications['notifyForNewManagers'] == null ||
54
                                    this.userNotifications['notifyForNewSubscribers'] == null)
55
                                    this.userNotifications = this.initiateUserNotifications();
56

  
57
                                console.log("Before: ", userNotifications);
58
                                console.log("After: ", this.userNotifications);
59
                            }
60
                        );
33 61
                    }
34 62
                }
35 63
            );
36 64
        });
37 65
    }
38 66

  
67
    public initiateUserNotifications() : UserNotificationsRights {
68
        var notificationRights: UserNotificationsRights = new UserNotificationsRights();
69

  
70
        notificationRights['notifyForNewManagers'] = true;
71
        notificationRights['notifyForNewSubscribers'] = true;
72
        notificationRights['managerEmail'] = this.userEmail;
73

  
74
        return notificationRights;
75
    }
76

  
77
    public updateUserNotifications() {
78
        if (this.communityId != null && this.communityId != '') {
79
            //this.showLoading = true;
80
            var userNotifications = this.parseUpdatedUserNotifications();
81
            console.log(userNotifications);
82
            this._manageUserNotificationService.updateUserNotification("http://scoobydoo.di.uoa.gr:8080/uoa-admin-tools/community/" + this.communityId + "/notifications", userNotifications).subscribe(
83

  
84
            );
85
        }
86
        this.resetChange();
87
    }
88

  
89
    private parseUpdatedUserNotifications() : {} {
90
        var userNotifications = {};
91

  
92
        userNotifications["notifyForNewManagers"] = this.userNotifications.notifyForNewManagers;
93
        userNotifications["notifyForNewSubscribers"] = this.userNotifications.notifyForNewSubscribers;
94

  
95
        if (this.userNotifications.managerEmail) {
96
            userNotifications["managerEmail"] = this.userNotifications.managerEmail;
97
        } else {
98
            if (Session.getUser()) {
99
                userNotifications["managerEmail"] = Session.getUserEmail();
100
            }
101
        }
102
        return userNotifications;
103
    }
104

  
105
    public resetForm(communityId:string) {
106
        if (communityId != null && communityId != '') {
107
            this._manageUserNotificationService.getUserNotification("http://scoobydoo.di.uoa.gr:8080/uoa-admin-tools/community/" + this.communityId + "/notifications", this.userEmail).subscribe(
108
                userNotifications => {
109
                    this.userNotifications = userNotifications;
110
                    console.log(userNotifications);
111
                }
112
            );
113
        }
114
        this.resetChange();
115
    }
116

  
117
    public changeValueForNewManagers(notifyForManagers : any) {
118
        this.userNotifications.notifyForNewManagers = !notifyForManagers;
119
        this.change();
120
    }
121

  
122
    public changeValueForNewSubscribers(notifyForSubscribers : any) {
123
        this.userNotifications.notifyForNewSubscribers = !notifyForSubscribers;
124
        this.change();
125
    }
126

  
127
    private change() {
128
        this.hasChanged = true;
129
        this.successfulSaveMessage = '';
130
        this.successfulResetMessage = '';
131
        // TODO remove after testing
132
        console.log('I have changed: I AM TRUE');
133
    }
134

  
135
    private resetChange() {
136
        this.hasChanged = false;
137
        // TODO remove after testing
138
        console.log('I have changed: I AM FALSE');
139
    }
39 140
}

Also available in: Unified diff