Skip to content

Commit

Permalink
Merge pull request #479 from NUM-Forschungsdatenplattform/release/v1.…
Browse files Browse the repository at this point in the history
…14.0

Release/v1.14.0
  • Loading branch information
richardbartha committed Aug 18, 2023
2 parents eaa05fe + e581550 commit aaa4a06
Show file tree
Hide file tree
Showing 65 changed files with 827 additions and 338 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ npm-debug.log
yarn-error.log
testem.log
/typings
.chrome/*

# System Files
.DS_Store
Expand Down
40 changes: 38 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "num-portal-webapp",
"version": "1.13.0",
"version": "1.14.0",
"scripts": {
"postinstall": "ngcc",
"ng": "ng",
Expand Down Expand Up @@ -34,6 +34,7 @@
"@angular/flex-layout": "^13.0.0-beta.36",
"@angular/forms": "^13.1.0",
"@angular/material": "^13.1.0",
"@angular/material-moment-adapter": "^13.1.0",
"@angular/platform-browser": "^13.1.0",
"@angular/platform-browser-dynamic": "^13.1.0",
"@angular/router": "^13.1.0",
Expand All @@ -57,6 +58,7 @@
"jest-preset-angular": "^11.0.1",
"jest-sonar-reporter": "^2.0.0",
"lodash-es": "^4.17.21",
"moment": "^2.29.4",
"monaco-editor": "^0.29.1",
"nanoid": "^3.1.30",
"ng-lint-staged": "^12.0.3",
Expand Down
3 changes: 2 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { OAuthInterceptor } from './core/interceptors/oauth.interceptor'
import { AuthService } from './core/auth/auth.service'
import { DateAdapter } from '@angular/material/core'
import { CustomDatePickerAdapter } from './core/adapter/date-picker-adapter'
import { MomentDateAdapter } from '@angular/material-moment-adapter'
import { OAuthStorage } from 'angular-oauth2-oidc'
import { WebpackTranslateLoader } from './webpack-translate-loader'
import { ErrorInterceptor } from './core/interceptors/error.interceptor'
Expand Down Expand Up @@ -82,7 +83,7 @@ import { ErrorInterceptor } from './core/interceptors/error.interceptor'
useClass: ErrorInterceptor,
multi: true,
},
{ provide: DateAdapter, useClass: CustomDatePickerAdapter },
{ provide: DateAdapter, useClass: MomentDateAdapter },
],
bootstrap: [AppComponent],
})
Expand Down
38 changes: 38 additions & 0 deletions src/app/core/constants/default-filter-organization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright 2021 Vitagroup AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { OrganizationUserFilterChipId } from 'src/app/shared/models/organization/organization-filter-chip.enum'
import { IOrganizationFilter } from 'src/app/shared/models/organization/organization-filter.interface'

export const DEFAULT_ORGANIZATION_FILTER: IOrganizationFilter = {
filterItem: [
{
id: OrganizationUserFilterChipId.OrganizationAll,
title: 'ORGANIZATION_MANAGEMENT.ALL',
isSelected: true,
},
{
id: OrganizationUserFilterChipId.OrganizationActive,
title: 'ORGANIZATION_MANAGEMENT.ACTIVE',
isSelected: false,
},
{
id: OrganizationUserFilterChipId.OrganizationInactive,
title: 'ORGANIZATION_MANAGEMENT.INACTIVE',
isSelected: false,
},
],
}
12 changes: 11 additions & 1 deletion src/app/core/constants/default-filter-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ export const DEFAULT_USER_FILTER: IUserFilter = {
{
id: UserFilterChipId.AllUser,
title: 'FILTER_CHIP.ALL',
isSelected: true,
isSelected: false,
},
{
id: UserFilterChipId.OrganizationUser,
title: 'FILTER_CHIP.ORGANIZATION',
isSelected: false,
},
{
id: UserFilterChipId.UserActive,
title: 'USER_MANAGEMENT.ACTIVE',
isSelected: true,
},
{
id: UserFilterChipId.UserInactive,
title: 'USER_MANAGEMENT.INACTIVE',
isSelected: false,
},
],
}
3 changes: 2 additions & 1 deletion src/app/core/helper/date-helper.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { TestBed } from '@angular/core/testing'

import { DateHelperService } from './date-helper.service'
import moment from 'moment'

describe('DateHelperService', () => {
let service: DateHelperService
Expand All @@ -39,7 +40,7 @@ describe('DateHelperService', () => {
})

it('Should convert dates as expected', () => {
const result = DateHelperService.getDateString(date)
const result = DateHelperService.getDateString(moment(dateString))
expect(result).toEqual('2021-01-02')
})

Expand Down
15 changes: 8 additions & 7 deletions src/app/core/helper/date-helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@
*/

import { Injectable } from '@angular/core'
import moment from 'moment'

@Injectable({
providedIn: 'root',
})
export class DateHelperService {
constructor() {}

static getDateString(date: Date): string {
const year = date.getFullYear()
const month = (date.getMonth() + 1).toString().padStart(2, '0')
const day = date.getDate().toString().padStart(2, '0')
static getDateString(date: moment.Moment): string {
const d = date.toDate()
const year = d.getFullYear()
const month = (d.getMonth() + 1).toString().padStart(2, '0')
const day = d.getDate().toString().padStart(2, '0')

return `${year}-${month}-${day}`
}

//we switched from javascript Date to Momentjs (https://momentjs.com/). If we need to support timebased funtions the cide below needs to be changed, too
static getTimeString(date: Date): string {
const hours = date.getHours().toString().padStart(2, '0')
const minutes = date.getMinutes().toString().padStart(2, '0')
Expand All @@ -50,7 +51,7 @@ export class DateHelperService {
}

static getIsoString(date: Date): string {
const dateString = this.getDateString(date)
const dateString = this.getDateString(moment(date))
const timeString = this.getTimeString(date)
const offset = this.getOffsetString(date)

Expand Down
20 changes: 13 additions & 7 deletions src/app/core/services/admin/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,8 @@ export class AdminService {
this.profileService.userProfileObservable$.subscribe((user) => (this.user = user))

this.filterConfigObservable$
.pipe(
skip(1),
throttleTime(this.throttleTime, undefined, { leading: true, trailing: true }),
switchMap((item) => this.getFilterResult$(item))
)
.subscribe((filterResult) => this.filteredApprovedUsersSubject$.next(filterResult))
.pipe(skip(1), throttleTime(this.throttleTime, undefined, { leading: true, trailing: true }))
.subscribe(() => this.filteredApprovedUsersSubject$)
}

private getUsers(approved: boolean, withRoles = false): Observable<IUser[]> {
Expand All @@ -92,7 +88,8 @@ export class AdminService {
): Observable<any> {
let qString = ''
if (page !== null && size !== null) {
qString = qString + '?page=' + page + '&size=' + size
qString =
qString + '?page=' + page + '&size=' + size + '&language=' + localStorage.getItem('lang')

for (const [key, value] of Object.entries(filters)) {
if (value !== null) {
Expand Down Expand Up @@ -183,6 +180,15 @@ export class AdminService {
.pipe(catchError(this.handleError))
}

changeUserEnabledStatus(userId: string, enabled: boolean): Observable<string> {
const httpOptions = {
responseType: 'text' as 'json',
}
return this.httpClient
.post<string>(`${this.baseUrl}/user/${userId}/status`, enabled, httpOptions)
.pipe(catchError(this.handleError))
}

setFilter(filterSet: IUserFilter): void {
this.filterConfigSubject$.next(filterSet)
this.filterSet = filterSet
Expand Down
39 changes: 17 additions & 22 deletions src/app/core/services/admin/test/admin.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/

import { HttpClient } from '@angular/common/http'
import { of, Subject, throwError, timer } from 'rxjs'
import { skipUntil } from 'rxjs/operators'
import { of, Subject, throwError } from 'rxjs'
import { AppConfigService } from 'src/app/config/app-config.service'
import { IUserFilter } from 'src/app/shared/models/user/user-filter.interface'
import { IUser } from 'src/app/shared/models/user/user.interface'
Expand Down Expand Up @@ -78,7 +77,7 @@ describe('AdminService', () => {
.then((_) => {})
.catch((_) => {})
expect(httpClient.get).toHaveBeenCalledWith(
'localhost/api/admin/user/all?page=0&size=2&filter%5Btype%5D=approved&sort=ASC&sortBy=firstName'
'localhost/api/admin/user/all?page=0&size=2&language=null&filter%5Btype%5D=approved&sort=ASC&sortBy=firstName'
)
expect(service.handleError).toHaveBeenCalled()
})
Expand Down Expand Up @@ -274,25 +273,6 @@ describe('AdminService', () => {
})
})

describe('When the filter logic fails to retrieve data', () => {
it('should result in an empty array', (done) => {
const anyService = service as any

jest.spyOn(httpClient, 'get').mockImplementation(() => throwError('error'))

service.filteredApprovedUsersObservable$
.pipe(skipUntil(timer(anyService.throttleTime / 2)))
.subscribe((result) => {
expect(result).toEqual([])
done()
})

setTimeout(() => {
service.refreshFilterResult()
}, anyService.throttleTime + 1)
})
})

describe('When passing in filters', () => {
test.each(adminFilterTestcases)('It should filter as expected', (testcase) => {
const anyService = service as any
Expand Down Expand Up @@ -334,6 +314,21 @@ describe('AdminService', () => {
httpOptions
)
})

it(`should call the api change status - with success`, () => {
const id = '123-456'
const httpOptions = {
responseType: 'text' as 'json',
}

jest.spyOn(httpClient, 'post')
service.changeUserEnabledStatus(id, true).subscribe()
expect(httpClient.post).toHaveBeenCalledWith(
`localhost/api/admin/user/${id}/status`,
true,
httpOptions
)
})
it(`should call the api - with error`, () => {
const id = '123-456'
const httpOptions = {
Expand Down
Loading

0 comments on commit aaa4a06

Please sign in to comment.