mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
54472: Intermediate commit
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { Community } from '../../core/shared/community.model';
|
import { Community } from '../../core/shared/community.model';
|
||||||
|
import { ComColDataService } from '../../core/data/comcol-data.service';
|
||||||
|
import { NormalizedCommunity } from '../../core/cache/models/normalized-community.model';
|
||||||
|
import { CommunityDataService } from '../../core/data/community-data.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-create-community',
|
selector: 'ds-create-community',
|
||||||
@@ -8,10 +11,15 @@ import { Community } from '../../core/shared/community.model';
|
|||||||
})
|
})
|
||||||
export class CreateCommunityPageComponent {
|
export class CreateCommunityPageComponent {
|
||||||
|
|
||||||
|
public constructor(private communityDataService: CommunityDataService) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
onSubmit(data: any) {
|
onSubmit(data: any) {
|
||||||
Object.assign(new Community(), {
|
const community = Object.assign(new Community(), {
|
||||||
// TODO: Create community object to add to rest
|
name: data.name
|
||||||
});
|
});
|
||||||
|
this.communityDataService.create(community);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,8 @@ import { ComColDataService } from './comcol-data.service';
|
|||||||
import { CommunityDataService } from './community-data.service';
|
import { CommunityDataService } from './community-data.service';
|
||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
|
import { AuthService } from '../auth/auth.service';
|
||||||
|
import { Community } from '../shared/community.model';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CollectionDataService extends ComColDataService<NormalizedCollection, Collection> {
|
export class CollectionDataService extends ComColDataService<NormalizedCollection, Collection> {
|
||||||
@@ -23,8 +25,13 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio
|
|||||||
protected store: Store<CoreState>,
|
protected store: Store<CoreState>,
|
||||||
protected cds: CommunityDataService,
|
protected cds: CommunityDataService,
|
||||||
protected objectCache: ObjectCacheService,
|
protected objectCache: ObjectCacheService,
|
||||||
protected halService: HALEndpointService
|
protected halService: HALEndpointService,
|
||||||
|
protected authService: AuthService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getName(collection: Collection) {
|
||||||
|
return collection.name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@ import { ResponseCacheEntry } from '../cache/response-cache.reducer';
|
|||||||
import { CommunityDataService } from './community-data.service';
|
import { CommunityDataService } from './community-data.service';
|
||||||
|
|
||||||
import { DataService } from './data.service';
|
import { DataService } from './data.service';
|
||||||
import { FindByIDRequest, PutRequest } from './request.models';
|
import { FindByIDRequest, PostRequest, PutRequest } from './request.models';
|
||||||
import { NormalizedObject } from '../cache/models/normalized-object.model';
|
import { NormalizedObject } from '../cache/models/normalized-object.model';
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||||
@@ -16,11 +16,15 @@ import { Community } from '../shared/community.model';
|
|||||||
import { Collection } from '../shared/collection.model';
|
import { Collection } from '../shared/collection.model';
|
||||||
import { distinctUntilChanged, map } from 'rxjs/operators';
|
import { distinctUntilChanged, map } from 'rxjs/operators';
|
||||||
import { configureRequest } from '../shared/operators';
|
import { configureRequest } from '../shared/operators';
|
||||||
|
import { AuthService } from '../auth/auth.service';
|
||||||
|
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
||||||
|
import { HttpHeaders } from '@angular/common/http';
|
||||||
|
|
||||||
export abstract class ComColDataService<TNormalized extends NormalizedObject, TDomain> extends DataService<TNormalized, TDomain> {
|
export abstract class ComColDataService<TNormalized extends NormalizedObject, TDomain> extends DataService<TNormalized, TDomain> {
|
||||||
protected abstract cds: CommunityDataService;
|
protected abstract cds: CommunityDataService;
|
||||||
protected abstract objectCache: ObjectCacheService;
|
protected abstract objectCache: ObjectCacheService;
|
||||||
protected abstract halService: HALEndpointService;
|
protected abstract halService: HALEndpointService;
|
||||||
|
protected abstract authService: AuthService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the scoped endpoint URL by fetching the object with
|
* Get the scoped endpoint URL by fetching the object with
|
||||||
@@ -66,9 +70,18 @@ export abstract class ComColDataService<TNormalized extends NormalizedObject, TD
|
|||||||
this.halService.getEndpoint(this.linkPath).pipe(
|
this.halService.getEndpoint(this.linkPath).pipe(
|
||||||
isNotEmptyOperator(),
|
isNotEmptyOperator(),
|
||||||
distinctUntilChanged(),
|
distinctUntilChanged(),
|
||||||
map((endpointURL: string) => new PutRequest(this.requestService.generateRequestId(), endpointURL, comcol)),
|
map((endpointURL: string) => {
|
||||||
|
const options: HttpOptions = Object.create({});
|
||||||
|
const headers = new HttpHeaders();
|
||||||
|
headers.append('Authentication', this.authService.buildAuthHeader());
|
||||||
|
options.headers = headers;
|
||||||
|
console.log(options);
|
||||||
|
return new PostRequest(this.requestService.generateRequestId(), endpointURL + '?name=' + this.getName(comcol), options);
|
||||||
|
}),
|
||||||
configureRequest(this.requestService)
|
configureRequest(this.requestService)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract getName(comcol: TDomain): string;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,7 @@ import { Community } from '../shared/community.model';
|
|||||||
import { ComColDataService } from './comcol-data.service';
|
import { ComColDataService } from './comcol-data.service';
|
||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
|
import { AuthService } from '../auth/auth.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CommunityDataService extends ComColDataService<NormalizedCommunity, Community> {
|
export class CommunityDataService extends ComColDataService<NormalizedCommunity, Community> {
|
||||||
@@ -23,7 +24,8 @@ export class CommunityDataService extends ComColDataService<NormalizedCommunity,
|
|||||||
protected rdbService: RemoteDataBuildService,
|
protected rdbService: RemoteDataBuildService,
|
||||||
protected store: Store<CoreState>,
|
protected store: Store<CoreState>,
|
||||||
protected objectCache: ObjectCacheService,
|
protected objectCache: ObjectCacheService,
|
||||||
protected halService: HALEndpointService
|
protected halService: HALEndpointService,
|
||||||
|
protected authService: AuthService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@@ -31,4 +33,8 @@ export class CommunityDataService extends ComColDataService<NormalizedCommunity,
|
|||||||
getEndpoint() {
|
getEndpoint() {
|
||||||
return this.halService.getEndpoint(this.linkPath);
|
return this.halService.getEndpoint(this.linkPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getName(community: Community) {
|
||||||
|
return community.name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user