Skip to content
Snippets Groups Projects
Commit 79a3788b authored by Kristof De Langhe's avatar Kristof De Langhe
Browse files

54472: Intermediate commit

parent aa73e874
Branches
Tags
No related merge requests found
import { Component } from '@angular/core';
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({
selector: 'ds-create-community',
......@@ -8,10 +11,15 @@ import { Community } from '../../core/shared/community.model';
})
export class CreateCommunityPageComponent {
public constructor(private communityDataService: CommunityDataService) {
}
onSubmit(data: any) {
Object.assign(new Community(), {
// TODO: Create community object to add to rest
const community = Object.assign(new Community(), {
name: data.name
});
this.communityDataService.create(community);
}
}
......@@ -11,6 +11,8 @@ import { ComColDataService } from './comcol-data.service';
import { CommunityDataService } from './community-data.service';
import { RequestService } from './request.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { AuthService } from '../auth/auth.service';
import { Community } from '../shared/community.model';
@Injectable()
export class CollectionDataService extends ComColDataService<NormalizedCollection, Collection> {
......@@ -23,8 +25,13 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio
protected store: Store<CoreState>,
protected cds: CommunityDataService,
protected objectCache: ObjectCacheService,
protected halService: HALEndpointService
protected halService: HALEndpointService,
protected authService: AuthService
) {
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 { 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 { HALEndpointService } from '../shared/hal-endpoint.service';
import { DSpaceObject } from '../shared/dspace-object.model';
......@@ -16,11 +16,15 @@ import { Community } from '../shared/community.model';
import { Collection } from '../shared/collection.model';
import { distinctUntilChanged, map } from 'rxjs/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> {
protected abstract cds: CommunityDataService;
protected abstract objectCache: ObjectCacheService;
protected abstract halService: HALEndpointService;
protected abstract authService: AuthService;
/**
* 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(
isNotEmptyOperator(),
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)
);
}
abstract getName(comcol: TDomain): string;
}
......@@ -11,6 +11,7 @@ import { Community } from '../shared/community.model';
import { ComColDataService } from './comcol-data.service';
import { RequestService } from './request.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { AuthService } from '../auth/auth.service';
@Injectable()
export class CommunityDataService extends ComColDataService<NormalizedCommunity, Community> {
......@@ -23,7 +24,8 @@ export class CommunityDataService extends ComColDataService<NormalizedCommunity,
protected rdbService: RemoteDataBuildService,
protected store: Store<CoreState>,
protected objectCache: ObjectCacheService,
protected halService: HALEndpointService
protected halService: HALEndpointService,
protected authService: AuthService
) {
super();
}
......@@ -31,4 +33,8 @@ export class CommunityDataService extends ComColDataService<NormalizedCommunity,
getEndpoint() {
return this.halService.getEndpoint(this.linkPath);
}
getName(community: Community) {
return community.name;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment