Skip to content

Commit 41d8fb5

Browse files
authored
Merge pull request #1638 from CSCfi/CSCTTV-3110v2
Cscttv 3110v2
2 parents 3b98c95 + d76c3d0 commit 41d8fb5

File tree

13 files changed

+237
-17684
lines changed

13 files changed

+237
-17684
lines changed

package-lock.json

Lines changed: 71 additions & 17473 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"@gorniv/ngx-transfer-http": "^2.2.9",
4545
"@nguniversal/common": "^13.1.1",
4646
"@nguniversal/express-engine": "^13.1.1",
47-
"angular-auth-oidc-client": "^13.1.0",
47+
"angular-auth-oidc-client": "^14.1.5",
4848
"array-flat-polyfill": "^1.0.1",
4949
"body-parser": "^1.19.2",
5050
"bootstrap": "^5.1.3",
@@ -123,4 +123,4 @@
123123
"optionalDependencies": {
124124
"esbuild-android-arm64": "^0.15.13"
125125
}
126-
}
126+
}

src/app/mydata/components/account-settings/account-settings.component.ts

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -187,57 +187,45 @@ export class AccountSettingsComponent implements OnInit {
187187
this.connProblemHideProfile = false;
188188
this.profileService
189189
.hideProfile()
190-
.pipe(take(1))
191-
.subscribe({
192-
next: (res: any) => {
190+
.then(
191+
(value) => {
193192
this.hideProfileInProgress = false;
194-
if (res.ok && res.body.success) {
195193
this.dialog.closeAll();
196194
sessionStorage.setItem('profileHidden', 'true');
197195
this.isProfileHidden = true;
198196
this.snackbarService.show(
199-
$localize`:@@profileHiddenToast:Profiilin piilottaminen onnistui. Profiilisi piilotetaan Tiedejatutkimus.fi -palvelusta muutaman minuutin kuluttua.`,
200-
'success'
201-
);
202-
197+
$localize`:@@profileHiddenToast:Profiilin piilottaminen onnistui. Profiilisi piilotetaan Tiedejatutkimus.fi -palvelusta muutaman minuutin kuluttua.`,
198+
'success'
199+
);
203200
//this.reset();
204-
}
205201
},
206-
error: (error) => {
202+
(reason) => {
207203
this.hideProfileInProgress = false;
208-
if (!error.ok) {
209-
this.connProblemHideProfile = true;
210-
}
211-
},
212-
});
204+
this.connProblemHideProfile = true;
205+
},);
213206
}
214207

215208
deleteProfile() {
216209
this.deleteProfileInProgress = true;
217210
this.connProblemDeleteProfile = false;
218211
this.profileService
219212
.deleteProfile()
220-
.pipe(take(1))
221-
.subscribe({
222-
next: (res: any) => {
213+
.then(
214+
(value) => {
223215
this.deleteProfileInProgress = false;
224-
if (res.ok && res.body.success) {
225-
this.dialog.closeAll();
226-
this.reset();
216+
this.dialog.closeAll();
217+
this.reset();
227218

228-
// Wait for dialog to close
229-
setTimeout(() => {
230-
this.oidcSecurityService.logoff();
219+
// Wait for dialog to close
220+
setTimeout(() => {
221+
this.oidcSecurityService.logoff();
231222
}, 500);
232-
}
223+
233224
},
234-
error: (error) => {
225+
(reason) => {
235226
this.deleteProfileInProgress = false;
236-
if (!error.ok) {
237-
this.connProblemDeleteProfile = true;
238-
}
239-
},
240-
});
227+
this.connProblemDeleteProfile = true;
228+
},);
241229
}
242230

243231
/*

src/app/mydata/components/profile/data-sources/data-sources-selection-actions/data-sources-selection-actions.component.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,24 @@ export class DataSourcesSelectionActionsComponent implements OnInit, OnDestroy {
153153
this.closeDialog();
154154
}
155155

156-
patchItems(action: Action) {
156+
async patchItems(action: Action) {
157157
const patchItemsArr = this.patchService.confirmedPayLoad;
158158

159159
const filteredItems = patchItemsArr.filter((item) =>
160160
action === 'publish' ? item.show : !item.show
161161
);
162162

163-
this.patchItemsSub = this.profileService
164-
.patchObjects(filteredItems)
165-
.pipe(take(1))
166-
.subscribe((res: HttpResponse<any>) => {
167-
if (res.body.success) {
163+
this.profileService
164+
.patchObjects(filteredItems).then(
165+
(value) => {
168166
this.onPatchSuccess.emit(filteredItems);
169167
// Enable hide profile button in account settings section, if it has been disabled
170168
sessionStorage.removeItem('profileHidden');
171169
this.snackbarService.showPatchMessage('success');
172-
} else {
170+
},
171+
(reason) => {
173172
this.snackbarService.showPatchMessage('error');
174-
}
175-
});
173+
},);
176174
}
177175

178176
// Used as callback function in filter pipe

src/app/mydata/components/profile/profile.component.ts

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -274,39 +274,16 @@ export class ProfileComponent implements OnInit, OnDestroy {
274274
* Patch items to backend
275275
*/
276276
private async patchItemsPromise() {
277-
return new Promise((resolve, reject) => {
278-
const patchItems = this.patchService.confirmedPayLoad;
279-
this.profileService
280-
.patchObjects(patchItems)
281-
.pipe(takeUntil(this.unsubscribe))
282-
.subscribe({
283-
next: (result) => {
284-
resolve(true);
285-
},
286-
error: (error) => {
287-
reject(error);
288-
},
289-
});
290-
});
277+
const patchItems = this.patchService.confirmedPayLoad;
278+
return this.profileService
279+
.patchObjects(patchItems);
291280
}
292281

293282
/*
294283
* Patch datasets to backend
295284
*/
296285
private async handleDatasetsPromise() {
297-
return new Promise((resolve, reject) => {
298-
this.datasetsService
299-
.addDatasets()
300-
.pipe(takeUntil(this.unsubscribe))
301-
.subscribe({
302-
next: (result) => {
303-
resolve(true);
304-
},
305-
error: (error) => {
306-
reject(error);
307-
},
308-
});
309-
});
286+
return this.datasetsService.addDatasets();
310287
}
311288

312289
/*

src/app/mydata/components/service-deployment/cancel-deployment/cancel-deployment.component.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ export class CancelDeploymentComponent implements OnInit {
4040

4141
if (token) {
4242
this.profileService
43-
.deleteAccount()
44-
.pipe(take(1))
45-
.subscribe((res: HttpResponse<any>) => {
46-
if (res.ok) {
47-
logout();
48-
}
49-
});
43+
.deleteAccount().then(
44+
(value) => {
45+
this.oidcSecurityService.logoff()
46+
},
47+
(reason) => {
48+
console.error(reason);
49+
},);
5050
} else {
5151
this.router.navigate(['/mydata']);
5252
}

src/app/mydata/components/service-deployment/orcid-data-fetch/orcid-data-fetch.component.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,39 @@ export class OrcidDataFetchComponent implements OnInit, OnDestroy {
3333
orcidDataFetchInfo3 = $localize`:@@orcidDataFetchInfo3:Tässä vaiheessa emme vielä julkaise profiiliasi.`;
3434
orcidDataFetchInfo4 = $localize`:@@orcidDataFetchInfo4:Voit hallinnoida tietojesi julkisuutta seuraavaksi aukeavassa profiilieditorissa.`;
3535

36-
fetchOrcidData() {
36+
37+
// Create profile when proceeding from step 4. Get ORCID data after profile creation
38+
async createProfile() {
39+
this.profileService
40+
.createProfile().then(
41+
(value) => {
42+
this.loading = true;
43+
this.getOrcidData();
44+
},
45+
(reason) => {
46+
console.error(reason);
47+
},);
48+
}
49+
50+
async fetchOrcidData() {
3751
if (!this.orcid) {
3852
this.profileService.handleOrcidNotLinked();
3953
} else {
40-
this.accountLinkSub = this.profileService
41-
.accountlink()
42-
.subscribe((response: { body: { success: string } }) => {
43-
if (response.body.success) {
44-
this.loading = true;
45-
this.createProfile();
46-
} else {
47-
console.error('Unable to link ORCID');
48-
}
49-
});
54+
this.profileService
55+
.accountlink().then(
56+
(value) => {
57+
this.loading = true;
58+
this.createProfile();
59+
},
60+
(reason) => {
61+
console.error(reason);
62+
console.error('Unable to link ORCID');
63+
},);
5064
}
5165
}
5266

53-
// Create profile when proceeding from step 4. Get ORCID data after profile creation
54-
createProfile() {
55-
this.createProfileSub = this.profileService
56-
.createProfile()
57-
.pipe(take(1))
58-
.subscribe((data: any) => {
59-
if (data.ok) {
60-
this.getOrcidData();
61-
} else {
62-
// TODO: Alert problem
63-
}
64-
});
65-
}
66-
6767
async getOrcidData() {
68-
const response: any = await this.profileService.getOrcidData().toPromise();
68+
const response: any = await this.profileService.getOrcidData();
6969
if (response.ok) {
7070
this.dialog.closeAll();
7171
this.loading = false;

src/app/mydata/components/service-deployment/service-deployment.component.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,20 @@ export class ServiceDeploymentComponent implements OnInit, OnDestroy {
7979

8080
// Initialize Identity Provider configuration and enable ORCID data fetch in step 4
8181
if (this.step === 4) {
82-
this.IDPLinkSub = this.profileService
83-
.accountlink()
84-
.pipe(switchMap(() => this.oidcSecurityService.forceRefreshSession()))
85-
.subscribe(() => {
86-
const idTokenPayload =
87-
this.oidcSecurityService.getPayloadFromIdToken();
88-
this.orcid = idTokenPayload.orcid;
89-
this.profileService.setUserData(idTokenPayload);
90-
});
82+
this.profileService
83+
.accountlink().then(
84+
(value) => {
85+
this.IDPLinkSub = this.oidcSecurityService.forceRefreshSession()
86+
.subscribe(() => {
87+
this.oidcSecurityService.getPayloadFromIdToken().subscribe(data => {
88+
this.orcid = data.orcid;
89+
this.profileService.setUserData(data);
90+
});
91+
});
92+
},
93+
(reason) => {
94+
console.error(reason);
95+
},);
9196
}
9297
});
9398

src/app/mydata/models/profile.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class ProfileAdapter implements Adapter<Profile> {
3737
) {}
3838

3939
adapt(item: any): Profile {
40-
const data = item.body.data;
40+
const data = item.data;
4141

4242
const mapModel = (adapter, data) => Object.values(adapter.adapt(data));
4343

src/app/mydata/resolvers/mydata-profile-resolver.service.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ export class MyDataProfileResolverService implements Resolve<any>, OnDestroy {
2424

2525
constructor(private profileService: ProfileService) {}
2626

27-
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
27+
async resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
28+
29+
await this.profileService
30+
.getProfileData().then((value) => {
31+
});
32+
2833
/*
2934
* Get MyData profile data before rendering route.
3035
* Data is stored in profile service.
@@ -35,18 +40,21 @@ export class MyDataProfileResolverService implements Resolve<any>, OnDestroy {
3540
return new Promise((resolve) => {
3641
this.profileService
3742
.getProfileData()
38-
.pipe(takeUntil(this.unsubscribeOnDestroy))
39-
.subscribe((response) => {
40-
// Store original data in service
41-
this.profileService.setCurrentProfileData(
42-
cloneDeep(response.profileData)
43-
);
44-
45-
resolve({
46-
name: getName(response.profileData),
47-
profileData: response.profileData,
48-
});
49-
});
43+
.then(
44+
(value) => {
45+
if (value) {
46+
this.profileService.setCurrentProfileData(
47+
cloneDeep(value.profileData)
48+
);
49+
resolve({
50+
name: getName(value.profileData),
51+
profileData: value.profileData,
52+
});
53+
}
54+
},
55+
(reason) => {
56+
console.error('error', reason);
57+
},);
5058
});
5159
} else {
5260
return {

0 commit comments

Comments
 (0)