diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index ea017153c..3b890bebb 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -100,7 +100,7 @@ export class HomePage implements OnInit { mobilefirstConnect() { - if(window['WLAuthorizationManager']){ + if(window['WLAuthorizationManager']) { if(window['WLAuthorizationManager'].obtainAccessToken) { window['WLAuthorizationManager'].obtainAccessToken("").then((token) => { @@ -130,7 +130,6 @@ export class HomePage implements OnInit { }); */ }); } - } diff --git a/src/app/services/notifications.service.ts b/src/app/services/notifications.service.ts index 35274bd9c..4e5ee8bda 100644 --- a/src/app/services/notifications.service.ts +++ b/src/app/services/notifications.service.ts @@ -49,55 +49,57 @@ export class NotificationsService { } else { const geturl = environment.apiURL + 'notifications/token'; - - if(window['WLAuthorizationManager'].obtainAccessToken) { - window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then( - (token) => { - console.log('Push Notification: Success ' + token); - - window['MFPPush'].initialize( - function (successResponse) { - console.log("Push notification Successfully Service intialized: " + successResponse); - }, - function (failureResponse) { - console.log("Push notification failure Service intialized: " + failureResponse); - } - ); - - window['MFPPush'].registerDevice(null, (successResponse) => { - console.log("Successfully registered: " + JSON.stringify(successResponse)); - console.log('token: ', successResponse.deviceId) - this.storageService.store(username, successResponse.deviceId); - this.storageService.get(username).then(value => { - console.log('STORAGE TOKEN', value) - this.storageService.get(AuthConnstants.USER).then(res => { - console.log('USERID', res); - const headers = { 'Authorization': 'Basic cGF1bG8ucGludG9AZ2FiaW5ldGVkaWdpdGFsLmxvY2FsOnRhYnRlc3RlQDAwNg==' }; - const body = { - UserId: res.UserId, - TokenId: successResponse.deviceId, - Status: 1, - Service: 1 - }; - this.http.post(`${geturl}`, body, { headers }).subscribe(data => { - console.log('TOKEN USER MIDLE', data); - }) + if(window['WLAuthorizationManager']) { + if(window['WLAuthorizationManager'].obtainAccessToken) { + window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then( + (token) => { + console.log('Push Notification: Success ' + token); + + window['MFPPush'].initialize( + function (successResponse) { + console.log("Push notification Successfully Service intialized: " + successResponse); + }, + function (failureResponse) { + console.log("Push notification failure Service intialized: " + failureResponse); + } + ); + + window['MFPPush'].registerDevice(null, (successResponse) => { + console.log("Successfully registered: " + JSON.stringify(successResponse)); + console.log('token: ', successResponse.deviceId) + this.storageService.store(username, successResponse.deviceId); + this.storageService.get(username).then(value => { + console.log('STORAGE TOKEN', value) + this.storageService.get(AuthConnstants.USER).then(res => { + console.log('USERID', res); + const headers = { 'Authorization': 'Basic cGF1bG8ucGludG9AZ2FiaW5ldGVkaWdpdGFsLmxvY2FsOnRhYnRlc3RlQDAwNg==' }; + const body = { + UserId: res.UserId, + TokenId: successResponse.deviceId, + Status: 1, + Service: 1 + }; + this.http.post(`${geturl}`, body, { headers }).subscribe(data => { + console.log('TOKEN USER MIDLE', data); + }) + }); + }); - - }); - }, - function (failureResponse) { - console.log("Successfully failue: " + JSON.stringify(failureResponse)); - } - ); - }, (error) => { - console.log('Push notification recived: failure ' + error.responseText); - console.log(JSON.stringify(error)); - } - ); + }, + function (failureResponse) { + console.log("Successfully failue: " + JSON.stringify(failureResponse)); + } + ); + }, (error) => { + console.log('Push notification recived: failure ' + error.responseText); + console.log(JSON.stringify(error)); + } + ); + } } + } } @@ -109,97 +111,104 @@ export class NotificationsService { } else { const geturl = environment.apiURL + 'notifications/token'; - if(window['WLAuthorizationManager'].obtainAccessToken) { - window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then( - (token) => { - console.log('Push Notification: Success ' + token); - - window['MFPPush'].initialize( - function (successResponse) { - console.log("Push notification Successfully Service intialized: " + successResponse); + if(window['WLAuthorizationManager']) { + if(window['WLAuthorizationManager'].obtainAccessToken) { + window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then( + (token) => { + console.log('Push Notification: Success ' + token); + + window['MFPPush'].initialize( + function (successResponse) { + console.log("Push notification Successfully Service intialized: " + successResponse); + }, + function (failureResponse) { + console.log("Push notification failure Service intialized: " + failureResponse); + } + ); + + window['MFPPush'].registerDevice(null, (successResponse) => { + console.log("Successfully registered: " + JSON.stringify(successResponse)); + console.log('token: ', successResponse.deviceId) + /* this.storageService.store(username, successResponse.deviceId); + this.storageService.get(username).then(value => { + console.log('STORAGE TOKEN', value) + this.storageService.get(AuthConnstants.USER).then(res => { + console.log('USERID', res); + const headers = { 'Authorization': 'Basic cGF1bG8ucGludG9AZ2FiaW5ldGVkaWdpdGFsLmxvY2FsOnRhYnRlc3RlQDAwNg==' }; + const body = { + UserId: res.UserId, + TokenId: successResponse.deviceId, + Status: 1, + Service: 1 + }; + this.http.post(`${geturl}`, body, { headers }).subscribe(data => { + console.log('TOKEN USER MIDLE', data); + }) + }); + + }); */ }, - function (failureResponse) { - console.log("Push notification failure Service intialized: " + failureResponse); - } - ); - - window['MFPPush'].registerDevice(null, (successResponse) => { - console.log("Successfully registered: " + JSON.stringify(successResponse)); - console.log('token: ', successResponse.deviceId) - /* this.storageService.store(username, successResponse.deviceId); - this.storageService.get(username).then(value => { - console.log('STORAGE TOKEN', value) - this.storageService.get(AuthConnstants.USER).then(res => { - console.log('USERID', res); - const headers = { 'Authorization': 'Basic cGF1bG8ucGludG9AZ2FiaW5ldGVkaWdpdGFsLmxvY2FsOnRhYnRlc3RlQDAwNg==' }; - const body = { - UserId: res.UserId, - TokenId: successResponse.deviceId, - Status: 1, - Service: 1 - }; - this.http.post(`${geturl}`, body, { headers }).subscribe(data => { - console.log('TOKEN USER MIDLE', data); - }) - }); - - }); */ - }, - function (failureResponse) { - console.log("Successfully failue: " + JSON.stringify(failureResponse)); - } - ); - }, (error) => { - console.log('Push notification recived: failure ' + error.responseText); - console.log(JSON.stringify(error)); - } - ); - } + function (failureResponse) { + console.log("Successfully failue: " + JSON.stringify(failureResponse)); + } + ); + }, (error) => { + console.log('Push notification recived: failure ' + error.responseText); + console.log(JSON.stringify(error)); + } + ); + } + } + } } async onReceviNotification() { - if(window['WLAuthorizationManager'].obtainAccessToken) { - window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then( - (token) => { - console.log('Push Notification: Success ' + token); - - window['MFPPush'].initialize( - function (successResponse) { - console.log("Push notification Successfully intialized: " + successResponse); - window['MFPPush'].registerNotificationsCallback(notificationReceived); - }, - function (failureResponse) { - console.log("Push notification failure intialized: " + failureResponse); + + if(window['WLAuthorizationManager']) { + if(window['WLAuthorizationManager'].obtainAccessToken) { + window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then( + (token) => { + console.log('Push Notification: Success ' + token); + + window['MFPPush'].initialize( + function (successResponse) { + console.log("Push notification Successfully intialized: " + successResponse); + window['MFPPush'].registerNotificationsCallback(notificationReceived); + }, + function (failureResponse) { + console.log("Push notification failure intialized: " + failureResponse); + } + ); + var notificationReceived = (message) => { + //this.jsonstore.createCollection('Notifications',message); + this.DataArray.push(message) + this.storageService.store("Notifications",JSON.stringify(this.DataArray)) + + console.log(message); + var data = JSON.parse(message.payload); + console.log(data.Service); + console.log(data.IdObject); + console.log(data.Object); + + if(message.actionName){ + this.notificatinsRoutes(data); + } else { + this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data); + } + } - ); - var notificationReceived = (message) => { - //this.jsonstore.createCollection('Notifications',message); - this.DataArray.push(message) - this.storageService.store("Notifications",JSON.stringify(this.DataArray)) - - console.log(message); - var data = JSON.parse(message.payload); - console.log(data.Service); - console.log(data.IdObject); - console.log(data.Object); - - if(message.actionName){ - this.notificatinsRoutes(data); - } else { - this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data); - } - + }, (error) => { + console.log('Push notification recived: failure ' + error.responseText); + console.log(JSON.stringify(error)); } - }, (error) => { - console.log('Push notification recived: failure ' + error.responseText); - console.log(JSON.stringify(error)); - } - ); + ); + } } + } notificatinsRoutes = (data) => { diff --git a/src/app/services/webnotifications.service.ts b/src/app/services/webnotifications.service.ts index 87de75dd7..85469e00e 100644 --- a/src/app/services/webnotifications.service.ts +++ b/src/app/services/webnotifications.service.ts @@ -47,41 +47,45 @@ export class WebNotificationsService { } async onReceviNotificationWeb() { - if(window['WLAuthorizationManager'].obtainAccessToken) { - window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then( - (token) => { - console.log('Push Notification: Success ' + token); - MFPPush.initialize( - function (successResponse) { - console.log("Push notification Successfully intialized: " + successResponse); - MFPPush.registerNotificationsCallback(notificationReceived); - }, - function (failureResponse) { - console.log("Push notification failure intialized: " + failureResponse); + if(window['WLAuthorizationManager']) { + if(window['WLAuthorizationManager'].obtainAccessToken) { + window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then( + (token) => { + console.log('Push Notification: Success ' + token); + + MFPPush.initialize( + function (successResponse) { + console.log("Push notification Successfully intialized: " + successResponse); + MFPPush.registerNotificationsCallback(notificationReceived); + }, + function (failureResponse) { + console.log("Push notification failure intialized: " + failureResponse); + } + ); + var notificationReceived = (message) => { + console.log(message); + var data = JSON.parse(message.payload); + console.log(data.Service); + console.log(data.IdObject); + console.log(data.Object); + + if(message.actionName){ + //this.notificatinsRoutes(data); + } else { + //this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data); + } + } - ); - var notificationReceived = (message) => { - console.log(message); - var data = JSON.parse(message.payload); - console.log(data.Service); - console.log(data.IdObject); - console.log(data.Object); - - if(message.actionName){ - //this.notificatinsRoutes(data); - } else { - //this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data); - } - + }, (error) => { + console.log('Push notification recived: failure ' + error.responseText); + console.log(JSON.stringify(error)); } - }, (error) => { - console.log('Push notification recived: failure ' + error.responseText); - console.log(JSON.stringify(error)); - } - ); + ); + } } + } /* getTokenByUserIdAndId(user, userID) { diff --git a/src/assets/js/index.js b/src/assets/js/index.js index ab6332424..7d2a23acd 100644 --- a/src/assets/js/index.js +++ b/src/assets/js/index.js @@ -1,38 +1,42 @@ function wlCommonInit() { - if(window['WLAuthorizationManager'].obtainAccessToken) { - window['WLAuthorizationManager'].obtainAccessToken("").then( - (token) => { - console.log('MobileFirst Server connect: Success ' + token); - - var resourceRequest = new WLResourceRequest("/adapters/javaAdapter/resource/greet/", - WLResourceRequest.GET - ); - - resourceRequest.setQueryParameter("name", "world"); - resourceRequest.send().then( - (response) => { - // Will display "Hello world" in an alert dialog. - console.log("Connect with JavaAdapter Success: " + response.responseText); - //this.MFPushNotification(); - }, - (error) => { - alert("Connect with JavaAdapter Failure: " + JSON.stringify(error)); - } - ); - }, (error) => { - console.log('MobileFirst Server connect: failure ' + error.responseText); - console.log(JSON.stringify(error)) - /* this.zone.run(() => { - alert("Bummer..."); - alert("Failed to connect to MobileFirst Server"); - }); */ - } - ); + if(window['WLAuthorizationManager']) { + if(window['WLAuthorizationManager'].obtainAccessToken) { + window['WLAuthorizationManager'].obtainAccessToken("").then( + (token) => { + console.log('MobileFirst Server connect: Success ' + token); + + var resourceRequest = new WLResourceRequest("/adapters/javaAdapter/resource/greet/", + WLResourceRequest.GET + ); + + resourceRequest.setQueryParameter("name", "world"); + resourceRequest.send().then( + (response) => { + // Will display "Hello world" in an alert dialog. + console.log("Connect with JavaAdapter Success: " + response.responseText); + //this.MFPushNotification(); + }, + (error) => { + alert("Connect with JavaAdapter Failure: " + JSON.stringify(error)); + } + ); + }, (error) => { + console.log('MobileFirst Server connect: failure ' + error.responseText); + console.log(JSON.stringify(error)) + /* this.zone.run(() => { + alert("Bummer..."); + alert("Failed to connect to MobileFirst Server"); + }); */ + } + ); + } } + + } \ No newline at end of file