Skip to content

Commit

Permalink
Merge 3f39752 into bb4aedc
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcambien committed Jun 30, 2020
2 parents bb4aedc + 3f39752 commit d4717f9
Show file tree
Hide file tree
Showing 21 changed files with 1,044 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/app/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ import { WorkflowActionDataService } from './data/workflow-action-data.service';
import { WorkflowAction } from './tasks/models/workflow-action-object.model';
import { MetadataSchemaDataService } from './data/metadata-schema-data.service';
import { MetadataFieldDataService } from './data/metadata-field-data.service';
import { SubmissionCcLicenseDataService } from './submission/submission-cc-license-data.service';
import { SubmissionCcLicence } from './submission/models/submission-cc-license.model';
import { SubmissionCcLicenceUrl } from './submission/models/submission-cc-license-url.model';
import { SubmissionCcLicenseUrlDataService } from './submission/submission-cc-license-url-data.service';

/**
* When not in production, endpoint responses can be mocked for testing purposes
Expand Down Expand Up @@ -208,6 +212,8 @@ const PROVIDERS = [
BrowseItemsResponseParsingService,
BrowseService,
ConfigResponseParsingService,
SubmissionCcLicenseDataService,
SubmissionCcLicenseUrlDataService,
SubmissionDefinitionsConfigService,
SubmissionFormsConfigService,
SubmissionRestService,
Expand Down Expand Up @@ -290,6 +296,8 @@ export const models =
License,
WorkflowItem,
WorkspaceItem,
SubmissionCcLicence,
SubmissionCcLicenceUrl,
SubmissionDefinitionsModel,
SubmissionFormsModel,
SubmissionSectionModel,
Expand Down
4 changes: 4 additions & 0 deletions src/app/core/shared/hal-resource.model.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { HALLink } from './hal-link.model';
import { deserialize } from 'cerialize';

/**
* Represents HAL resources.
*
* A HAL resource has a _links section with at least a self link.
*/
export class HALResource {

/**
* The {@link HALLink}s for this {@link HALResource}
*/
@deserialize
_links: {

/**
* The {@link HALLink} that refers to this {@link HALResource}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ResourceType } from '../../shared/resource-type';

/**
* The resource type for License
*
* Needs to be in a separate file to prevent circular
* dependencies in webpack.
*/
export const SUBMISSION_CC_LICENSE_URL = new ResourceType('submissioncclicenseUrl');
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ResourceType } from '../../shared/resource-type';

/**
* The resource type for License
*
* Needs to be in a separate file to prevent circular
* dependencies in webpack.
*/
export const SUBMISSION_CC_LICENSE = new ResourceType('submissioncclicense');
23 changes: 23 additions & 0 deletions src/app/core/submission/models/submission-cc-license-url.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { autoserialize, inheritSerialization } from 'cerialize';
import { typedObject } from '../../cache/builders/build-decorators';
import { excludeFromEquals } from '../../utilities/equals.decorators';
import { ResourceType } from '../../shared/resource-type';
import { HALResource } from '../../shared/hal-resource.model';
import { SUBMISSION_CC_LICENSE_URL } from './submission-cc-licence-link.resource-type';

@typedObject
@inheritSerialization(HALResource)
export class SubmissionCcLicenceUrl extends HALResource {

static type = SUBMISSION_CC_LICENSE_URL;

/**
* The object type
*/
@excludeFromEquals
@autoserialize
type: ResourceType;

@autoserialize
url: string;
}
42 changes: 42 additions & 0 deletions src/app/core/submission/models/submission-cc-license.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { autoserialize, inheritSerialization } from 'cerialize';
import { typedObject } from '../../cache/builders/build-decorators';
import { excludeFromEquals } from '../../utilities/equals.decorators';
import { ResourceType } from '../../shared/resource-type';
import { HALResource } from '../../shared/hal-resource.model';
import { SUBMISSION_CC_LICENSE } from './submission-cc-licence.resource-type';

@typedObject
@inheritSerialization(HALResource)
export class SubmissionCcLicence extends HALResource {

static type = SUBMISSION_CC_LICENSE;

/**
* The object type
*/
@excludeFromEquals
@autoserialize
type: ResourceType;

@autoserialize
id: string;

@autoserialize
name: string;

@autoserialize
fields: Field[];
}

export interface Field {
id: string;
label: string;
description: string;
enums: Option[];
}

export interface Option {
id: string;
label: string;
description: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Option } from './submission-cc-license.model';

/**
* An interface to represent the submission's creative commons license section data.
*/
export interface WorkspaceitemSectionCcLicenseObject {
ccLicense?: {
id: string;
fields: {
[fieldId: string]: Option;
}
};
uri?: string;
accepted?: boolean;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { WorkspaceitemSectionFormObject } from './workspaceitem-section-form.model';
import { WorkspaceitemSectionLicenseObject } from './workspaceitem-section-license.model';
import { WorkspaceitemSectionUploadObject } from './workspaceitem-section-upload.model';
import { WorkspaceitemSectionCcLicenseObject } from './workspaceitem-section-cc-license.model';

/**
* An interface to represent submission's section object.
Expand All @@ -17,4 +18,5 @@ export type WorkspaceitemSectionDataType
= WorkspaceitemSectionUploadObject
| WorkspaceitemSectionFormObject
| WorkspaceitemSectionLicenseObject
| WorkspaceitemSectionCcLicenseObject
| string;
34 changes: 34 additions & 0 deletions src/app/core/submission/submission-cc-license-data.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { dataService } from '../cache/builders/build-decorators';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { ObjectCacheService } from '../cache/object-cache.service';
import { CoreState } from '../core.reducers';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { DataService } from '../data/data.service';
import { RequestService } from '../data/request.service';
import { SUBMISSION_CC_LICENSE } from './models/submission-cc-licence.resource-type';
import { SubmissionCcLicence } from './models/submission-cc-license.model';
import { DefaultChangeAnalyzer } from '../data/default-change-analyzer.service';

@Injectable()
@dataService(SUBMISSION_CC_LICENSE)
export class SubmissionCcLicenseDataService extends DataService<SubmissionCcLicence> {

protected linkPath = 'submissioncclicenses';

constructor(
protected comparator: DefaultChangeAnalyzer<SubmissionCcLicence>,
protected halService: HALEndpointService,
protected http: HttpClient,
protected notificationsService: NotificationsService,
protected objectCache: ObjectCacheService,
protected rdbService: RemoteDataBuildService,
protected requestService: RequestService,
protected store: Store<CoreState>,
) {
super();
}
}
76 changes: 76 additions & 0 deletions src/app/core/submission/submission-cc-license-url-data.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { dataService } from '../cache/builders/build-decorators';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { ObjectCacheService } from '../cache/object-cache.service';
import { CoreState } from '../core.reducers';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { DataService } from '../data/data.service';
import { RequestService } from '../data/request.service';
import { DefaultChangeAnalyzer } from '../data/default-change-analyzer.service';
import { SubmissionCcLicenceUrl } from './models/submission-cc-license-url.model';
import { SUBMISSION_CC_LICENSE_URL } from './models/submission-cc-licence-link.resource-type';
import { Field, Option, SubmissionCcLicence } from './models/submission-cc-license.model';
import { Observable } from 'rxjs';
import { filter, map, switchMap } from 'rxjs/operators';
import { getRemoteDataPayload, getSucceededRemoteData } from '../shared/operators';
import { isNotEmpty } from '../../shared/empty.util';

@Injectable()
@dataService(SUBMISSION_CC_LICENSE_URL)
export class SubmissionCcLicenseUrlDataService extends DataService<SubmissionCcLicenceUrl> {

protected linkPath = 'submissioncclicenseUrl-search';

constructor(
protected comparator: DefaultChangeAnalyzer<SubmissionCcLicenceUrl>,
protected halService: HALEndpointService,
protected http: HttpClient,
protected notificationsService: NotificationsService,
protected objectCache: ObjectCacheService,
protected rdbService: RemoteDataBuildService,
protected requestService: RequestService,
protected store: Store<CoreState>,
) {
super();
}

/**
* Get the link to the Creative Commons license corresponding to the given type and options.
* @param ccLicense the Creative Commons license type
* @param options the selected options of the license fields
*/
getCcLicenseLink(ccLicense: SubmissionCcLicence, options: Map<Field, Option>): Observable<string> {

return this.getSearchByHref(
'rightsByQuestions',{
searchParams: [
{
fieldName: 'license',
fieldValue: ccLicense.id
},
...ccLicense.fields.map(
(field) => {
return {
fieldName: `answer_${field.id}`,
fieldValue: options.get(field).id,
}
}),
]
}
).pipe(
switchMap((href) => this.findByHref(href)),
getSucceededRemoteData(),
getRemoteDataPayload(),
map((response) => response.url),
);
}

protected getSearchEndpoint(searchMethod: string): Observable<string> {
return this.halService.getEndpoint(`${this.linkPath}`).pipe(
filter((href: string) => isNotEmpty(href)),
map((href: string) => `${href}/${searchMethod}`));
}
}
31 changes: 31 additions & 0 deletions src/app/shared/ds-select/ds-select.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div>

<div ngbDropdown class="btn-group" (openChange)="toggled.emit($event)">

<div class="input-group-prepend" *ngIf="label">
<span id="dsSelectMenuLabel" class="input-group-text">
{{ label | translate }}
</span>
</div>

<button aria-describedby="dsSelectMenuLabel"
id="dsSelectMenuButton"
class="btn btn-outline-primary selection"
(blur)="close.emit($event)"
(click)="close.emit($event)"
[disabled]="disabled"
ngbDropdownToggle>
<ng-content select=".selection"></ng-content>
</button>

<div ngbDropdownMenu
class="dropdown-menu"
id="dsSelectDropdownMenu"
aria-labelledby="dsSelectMenuButton">
<div aria-labelledby="dropdownMenuButton">
<ng-content select=".menu"></ng-content>
</div>
</div>
</div>

</div>
Empty file.
30 changes: 30 additions & 0 deletions src/app/shared/ds-select/ds-select.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { DsSelectComponent } from './ds-select.component';
import { TranslateModule } from '@ngx-translate/core';

describe('DsSelectComponent', () => {
let component: DsSelectComponent;
let fixture: ComponentFixture<DsSelectComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
],
declarations: [
DsSelectComponent,
],
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(DsSelectComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
36 changes: 36 additions & 0 deletions src/app/shared/ds-select/ds-select.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';

/**
* Component which represent a DSpace dropdown selector.
*/
@Component({
selector: 'ds-select',
templateUrl: './ds-select.component.html',
styleUrls: ['./ds-select.component.scss']
})
export class DsSelectComponent {

/**
* An optional label for the dropdown selector.
*/
@Input()
label: string;

/**
* Whether the dropdown selector is disabled.
*/
@Input()
disabled: boolean;

/**
* Emits an event when the dropdown selector is opened or closed.
*/
@Output()
toggled = new EventEmitter();

/**
* Emits an event when the dropdown selector or closed.
*/
@Output()
close = new EventEmitter();
}
2 changes: 2 additions & 0 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ import { ResourcePolicyResolver } from './resource-policies/resolvers/resource-p
import { EpersonSearchBoxComponent } from './resource-policies/form/eperson-group-list/eperson-search-box/eperson-search-box.component';
import { GroupSearchBoxComponent } from './resource-policies/form/eperson-group-list/group-search-box/group-search-box.component';
import { CollectionDropdownComponent } from './collection-dropdown/collection-dropdown.component';
import { DsSelectComponent } from './ds-select/ds-select.component';

const MODULES = [
// Do NOT include UniversalModule, HttpModule, or JsonpModule here
Expand Down Expand Up @@ -279,6 +280,7 @@ const COMPONENTS = [
DsDynamicFormGroupComponent,
DsDynamicFormArrayComponent,
DsDatePickerInlineComponent,
DsSelectComponent,
ErrorComponent,
FormComponent,
LangSwitchComponent,
Expand Down

0 comments on commit d4717f9

Please sign in to comment.