forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
ufal/fe-license-static-pages-are-missing (#380)
* Added static files and redirection * Html content is loaded from the static file and rendered in the component. * The html file content is showed in the `static/` route with the error page. The translation works. * Created routing for the `licenses` page and changed administrator license table to `licenses/manage-table` path * Show all licenses data. * All licenses are filtered by license label - PUB, ACA, RES * Added loading bar * Added redirect from license selector * Fixed tests. * Refactoring * Fixed lint error - unused import * Added docs and translations. * Removed accidentally added semicolon. * Added simple test if the html file content will be loaded.
1 parent
1e4ea47
commit 6f146c2
Showing
61 changed files
with
12,194 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/app/clarin-licenses/clarin-all-licenses-page/clarin-all-licenses-page.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<div class="container"> | ||
<div class="card"> | ||
<h5 class="card-header">{{ 'clarin.license.all-page.title' | translate }}</h5> | ||
<ds-loading *ngIf="isLoading" class="text-center"></ds-loading> | ||
<div class="card-body" *ngFor="let clarinLicense of (licensesRD$ | async)"> | ||
<h6 class="card-header border-bottom-0 license-card-border"><a [href]="clarinLicense.definition">{{ clarinLicense.name }}</a></h6> | ||
<div class="card-body rounded-bottom license-card-border"> | ||
<div> | ||
<div><b>{{'clarin.license.all-page.source' | translate}}</b></div> | ||
<div><a [href]="clarinLicense.definition">{{ clarinLicense.definition }}</a></div> | ||
</div> | ||
<div> | ||
<div><b>{{'clarin.license.all-page.labels' | translate}}</b></div> | ||
<span [ngClass]="'px-1 d-inline label label-license' + ' label-' + clarinLicense.clarinLicenseLabel.label + ' rounded text-white'"> | ||
{{clarinLicense.clarinLicenseLabel.title}} | ||
</span> | ||
<span *ngFor="let clarinLicenseLabel of clarinLicense.extendedClarinLicenseLabels" | ||
class="px-1 label label-default rounded text-white ml-1"> | ||
{{clarinLicenseLabel.title}} | ||
</span> | ||
</div> | ||
<div> | ||
<div><b>{{'clarin.license.all-page.extra-information' | translate}}</b></div> | ||
<span *ngIf="clarinLicense.requiredInfo == null">{{'clarin.license.all-page.extra-information.default' | translate}} | ||
</span> | ||
<span *ngFor="let requiredInformation of clarinLicense.requiredInfo" | ||
class="px-1 label label-default rounded text-white mr-1"> | ||
{{requiredInformation?.value}} | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
22 changes: 22 additions & 0 deletions
22
src/app/clarin-licenses/clarin-all-licenses-page/clarin-all-licenses-page.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.label-PUB { | ||
background-color: #5cb811 !important; | ||
color: white !important; | ||
} | ||
|
||
.label-RES { | ||
background-color: #c62d1f !important; | ||
color: white !important; | ||
} | ||
|
||
.label-ACA, .label-PDT { | ||
background-color: #ffab23 !important; | ||
color: white !important; | ||
} | ||
|
||
.label-default { | ||
background-color: #999 !important; | ||
} | ||
|
||
.license-card-border { | ||
border: 1px solid #e3e3e3; | ||
} |
44 changes: 44 additions & 0 deletions
44
src/app/clarin-licenses/clarin-all-licenses-page/clarin-all-licenses-page.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ClarinAllLicensesPageComponent } from './clarin-all-licenses-page.component'; | ||
import { createdLicenseRD$, mockLicenseRD$ } from '../../shared/testing/clarin-license-mock'; | ||
import { of as observableOf } from 'rxjs'; | ||
import { ClarinLicenseDataService } from '../../core/data/clarin/clarin-license-data.service'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
|
||
describe('ClarinAllLicensesPageComponent', () => { | ||
let component: ClarinAllLicensesPageComponent; | ||
let fixture: ComponentFixture<ClarinAllLicensesPageComponent>; | ||
let clarinLicenseDataService: ClarinLicenseDataService; | ||
|
||
beforeEach(async () => { | ||
clarinLicenseDataService = jasmine.createSpyObj('clarinLicenseService', { | ||
findAll: mockLicenseRD$, | ||
create: createdLicenseRD$, | ||
put: createdLicenseRD$, | ||
searchBy: mockLicenseRD$, | ||
getLinkPath: observableOf('') | ||
}); | ||
|
||
await TestBed.configureTestingModule({ | ||
declarations: [ ClarinAllLicensesPageComponent ], | ||
imports: [ | ||
TranslateModule.forRoot(), | ||
], | ||
providers: [ | ||
{ provide: ClarinLicenseDataService, useValue: clarinLicenseDataService }, | ||
] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ClarinAllLicensesPageComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
71 changes: 71 additions & 0 deletions
71
src/app/clarin-licenses/clarin-all-licenses-page/clarin-all-licenses-page.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { ClarinLicense } from '../../core/shared/clarin/clarin-license.model'; | ||
import { ClarinLicenseDataService } from '../../core/data/clarin/clarin-license-data.service'; | ||
import { getFirstSucceededRemoteListPayload } from '../../core/shared/operators'; | ||
import { FindListOptions } from '../../core/data/find-list-options.model'; | ||
|
||
@Component({ | ||
selector: 'ds-clarin-all-licenses-page', | ||
templateUrl: './clarin-all-licenses-page.component.html', | ||
styleUrls: ['./clarin-all-licenses-page.component.scss'] | ||
}) | ||
export class ClarinAllLicensesPageComponent implements OnInit { | ||
|
||
/** | ||
* The list of ClarinLicense object as BehaviorSubject object | ||
*/ | ||
licensesRD$: BehaviorSubject<ClarinLicense[]> = new BehaviorSubject<ClarinLicense[]>(null); | ||
|
||
/** | ||
* If the request isn't processed show to loading bar. | ||
*/ | ||
isLoading = false; | ||
|
||
constructor(private clarinLicenseService: ClarinLicenseDataService) { } | ||
|
||
ngOnInit(): void { | ||
this.loadAllLicenses(); | ||
} | ||
|
||
loadAllLicenses() { | ||
this.isLoading = true; | ||
|
||
const options = new FindListOptions(); | ||
options.currentPage = 0; | ||
// Load all licenses | ||
options.elementsPerPage = 1000; | ||
return this.clarinLicenseService.findAll(options, false) | ||
.pipe(getFirstSucceededRemoteListPayload()) | ||
.subscribe(res => { | ||
this.licensesRD$.next(this.filterLicensesByLicenseLabel(res)); | ||
this.isLoading = false; | ||
}); | ||
} | ||
|
||
/** | ||
* Show PUB licenses at first, then ACA and RES | ||
* @private | ||
*/ | ||
private filterLicensesByLicenseLabel(clarinLicensesResponse: ClarinLicense[]) { | ||
// Show PUB licenses as first. | ||
const pubLicenseArray = []; | ||
// Then show ACA and RES licenses. | ||
const acaResLicenseArray = []; | ||
|
||
clarinLicensesResponse?.forEach(clarinLicense => { | ||
if (clarinLicense?.clarinLicenseLabel?.label === 'PUB') { | ||
pubLicenseArray.push(clarinLicense); | ||
} else { | ||
acaResLicenseArray.push(clarinLicense); | ||
} | ||
}); | ||
|
||
// Sort acaResLicenseArray by the license label (ACA, RES) | ||
acaResLicenseArray.sort((a, b) => a.clarinLicenseLabel?.label?.localeCompare(b.clarinLicenseLabel?.label)); | ||
|
||
// Concat two array into one. | ||
return pubLicenseArray.concat(acaResLicenseArray); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { catchError } from 'rxjs/operators'; | ||
import { of as observableOf } from 'rxjs'; | ||
|
||
/** | ||
* Service for loading static `.html` files stored in the `/static-files` folder. | ||
*/ | ||
@Injectable() | ||
export class HtmlContentService { | ||
constructor(private http: HttpClient) {} | ||
|
||
/** | ||
* Load `.html` file content or return empty string if an error. | ||
* @param url file location | ||
*/ | ||
fetchHtmlContent(url: string) { | ||
// catchError -> return empty value. | ||
return this.http.get(url, { responseType: 'text' }).pipe( | ||
catchError(() => observableOf(''))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Constants for `/static` route. | ||
*/ | ||
export const STATIC_PAGE_PATH = 'static'; | ||
export const STATIC_FILES_PROJECT_PATH = 'static-files'; | ||
export const STATIC_FILES_DEFAULT_ERROR_PAGE_PATH = STATIC_FILES_PROJECT_PATH + '/' + 'error.html'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { RouterModule, Routes } from '@angular/router'; | ||
import { StaticPageComponent } from './static-page.component'; | ||
|
||
const routes: Routes = [ | ||
{ | ||
path: '', | ||
children: [ | ||
{ path: '', component: StaticPageComponent }, | ||
{ path: ':htmlFileName', component: StaticPageComponent }, | ||
], | ||
}, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [RouterModule.forChild(routes)], | ||
exports: [RouterModule] | ||
}) | ||
export class StaticPageRoutingModule { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="container" > | ||
<div [innerHTML]="(htmlContent | async)"></div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/** | ||
File for styling the `static-page` component. | ||
*/ |
Oops, something went wrong.