Skip to content
Snippets Groups Projects
Commit e0ed960d authored by lotte's avatar lotte
Browse files

refactoring continued

parent a35dffbe
No related branches found
No related tags found
No related merge requests found
import { Component, OnInit } from '@angular/core';
import {Collection} from '../../core/shared/collection.model';
import {CollectionDataService} from '../../core/data/collection-data.service';
import { Observable } from 'rxjs';
import { Component } from '@angular/core';
import { CommunityDataService } from '../../core/data/community-data.service';
import { RouteService } from '../../shared/services/route.service';
import { Router } from '@angular/router';
import { RemoteData } from '../../core/data/remote-data';
import { isNotEmpty, isNotUndefined } from '../../shared/empty.util';
import { take } from 'rxjs/operators';
import { getSucceededRemoteData } from '../../core/shared/operators';
import {Community} from '../../core/shared/community.model';
import {CommunityDataService} from '../../core/data/community-data.service';
import { CreateComColPageComponent } from '../../comcol-forms/create-comcol-page/create-comcol-page.component';
import { NormalizedCollection } from '../../core/cache/models/normalized-collection.model';
import { Collection } from '../../core/shared/collection.model';
import { CollectionDataService } from '../../core/data/collection-data.service';
@Component({
selector: 'ds-create-collection',
styleUrls: ['./create-collection-page.component.scss'],
templateUrl: './create-collection-page.component.html'
selector: 'ds-create-community',
styleUrls: ['./create-community-page.component.scss'],
templateUrl: './create-community-page.component.html'
})
export class CreateCommunityPageComponent implements OnInit {
public parentUUID$: Observable<string>;
public parentRD$: Observable<RemoteData<Community>>;
export class CreateCommunityPageComponent extends CreateComColPageComponent<Collection, NormalizedCollection> {
protected frontendURL = 'collections';
public constructor(
private communityDataService: CommunityDataService,
private collectionDataService: CollectionDataService,
private routeService: RouteService,
private router: Router
protected communityDataService: CommunityDataService,
protected collectionDataService: CollectionDataService,
protected routeService: RouteService,
protected router: Router
) {
}
ngOnInit(): void {
this.parentUUID$ = this.routeService.getQueryParameterValue('parent');
this.parentUUID$.subscribe((parentID: string) => {
if (isNotEmpty(parentID)) {
this.parentRD$ = this.communityDataService.findById(parentID);
}
});
super(collectionDataService, communityDataService, routeService, router);
}
onSubmit(collection: Collection) {
this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => {
this.collectionDataService.create(collection, uuid)
.pipe(getSucceededRemoteData())
.subscribe((collectionRD: RemoteData<Community>) => {
if (isNotUndefined(collectionRD)) {
const newUUID = collectionRD.payload.uuid;
this.router.navigate(['/collections/' + newUUID]);
}
});
});
}
}
......@@ -4,13 +4,15 @@ import { CommunityDataService } from '../../core/data/community-data.service';
import { RouteService } from '../../shared/services/route.service';
import { Router } from '@angular/router';
import { CreateComColPageComponent } from '../../comcol-forms/create-comcol-page/create-comcol-page.component';
import { NormalizedCommunity } from '../../core/cache/models/normalized-community.model';
@Component({
selector: 'ds-create-community',
styleUrls: ['./create-community-page.component.scss'],
templateUrl: './create-community-page.component.html'
})
export class CreateCommunityPageComponent extends CreateComColPageComponent<Community> {
export class CreateCommunityPageComponent extends CreateComColPageComponent<Community, NormalizedCommunity> {
protected frontendURL = 'communities';
public constructor(
protected communityDataService: CommunityDataService,
protected routeService: RouteService,
......
......@@ -10,20 +10,21 @@ import { take } from 'rxjs/operators';
import { getSucceededRemoteData } from '../../core/shared/operators';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { DataService } from '../../core/data/data.service';
import { NormalizedDSpaceObject } from '../../core/cache/models/normalized-dspace-object.model';
@Component({
selector: 'ds-create-community',
styleUrls: ['./create-community-page.component.scss'],
templateUrl: './create-community-page.component.html'
})
export class CreateComColPageComponent<T extends DSpaceObject> implements OnInit {
export class CreateComColPageComponent<TDomain extends DSpaceObject, TNormalized extends NormalizedDSpaceObject> implements OnInit {
protected frontendURL: string;
public parentUUID$: Observable<string>;
public parentRD$: Observable<RemoteData<T>>;
public parentRD$: Observable<RemoteData<Community>>;
public constructor(
protected dsoDataService: DataService<T>,
protected parentoDataService: CommunityDataService,
protected dsoDataService: DataService<TNormalized, TDomain>,
protected parentDataService: CommunityDataService,
protected routeService: RouteService,
protected router: Router
) {
......@@ -34,19 +35,19 @@ export class CreateComColPageComponent<T extends DSpaceObject> implements OnInit
this.parentUUID$ = this.routeService.getQueryParameterValue('parent');
this.parentUUID$.subscribe((parentID: string) => {
if (isNotEmpty(parentID)) {
this.parentRD$ = this.parentoDataService.findById(parentID);
this.parentRD$ = this.parentDataService.findById(parentID);
}
});
}
onSubmit(dso: T) {
onSubmit(dso: TDomain) {
this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => {
this.dsoDataService.create(dso, uuid)
.pipe(getSucceededRemoteData())
.subscribe((dsoRD: RemoteData<Community>) => {
.subscribe((dsoRD: RemoteData<TDomain>) => {
if (isNotUndefined(dsoRD)) {
const newUUID = dsoRD.payload.uuid;
this.router.navigate([frontendURL + newUUID]);
this.router.navigate([this.frontendURL + newUUID]);
}
});
});
......
import {Component, OnInit} from '@angular/core';
import { Community } from '../../core/shared/community.model';
import { Observable } from 'rxjs';
import { RouteService } from '../../shared/services/route.service';
import { ActivatedRoute, Router } from '@angular/router';
import { RemoteData } from '../../core/data/remote-data';
import { isNotUndefined } from '../../shared/empty.util';
import { first, map } from 'rxjs/operators';
import { getSucceededRemoteData } from '../../core/shared/operators';
import { DataService } from '../../core/data/data.service';
import { NormalizedDSpaceObject } from '../../core/cache/models/normalized-dspace-object.model';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
@Component({
selector: 'ds-edit-community',
styleUrls: ['./edit-community-page.component.scss'],
templateUrl: './edit-community-page.component.html'
})
export class EditComColPageComponent<TDomain extends DSpaceObject, TNormalized extends NormalizedDSpaceObject> implements OnInit {
protected frontendURL: string;
public dsoRD$: Observable<RemoteData<Community>>;
public constructor(
protected dsoDataService: DataService<TNormalized, TDomain>,
private routeService: RouteService,
private router: Router,
private route: ActivatedRoute
) {
}
ngOnInit(): void {
this.dsoRD$ = this.route.data.pipe(first(), map((data) => data.dso));
}
onSubmit(dso: TDomain) {
this.dsoDataService.update(dso)
.pipe(getSucceededRemoteData())
.subscribe((dsoRD: RemoteData<TDomain>) => {
if (isNotUndefined(dsoRD)) {
const newUUID = dsoRD.payload.uuid;
this.router.navigate([this.frontendURL + newUUID]);
}
});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment