mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-16 14:33:03 +00:00
refactoring continued
This commit is contained in:
@@ -1,55 +1,26 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import {Collection} from '../../core/shared/collection.model';
|
import { CommunityDataService } from '../../core/data/community-data.service';
|
||||||
import {CollectionDataService} from '../../core/data/collection-data.service';
|
|
||||||
import { Observable } from 'rxjs';
|
|
||||||
import { RouteService } from '../../shared/services/route.service';
|
import { RouteService } from '../../shared/services/route.service';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { RemoteData } from '../../core/data/remote-data';
|
import { CreateComColPageComponent } from '../../comcol-forms/create-comcol-page/create-comcol-page.component';
|
||||||
import { isNotEmpty, isNotUndefined } from '../../shared/empty.util';
|
import { NormalizedCollection } from '../../core/cache/models/normalized-collection.model';
|
||||||
import { take } from 'rxjs/operators';
|
import { Collection } from '../../core/shared/collection.model';
|
||||||
import { getSucceededRemoteData } from '../../core/shared/operators';
|
import { CollectionDataService } from '../../core/data/collection-data.service';
|
||||||
import {Community} from '../../core/shared/community.model';
|
|
||||||
import {CommunityDataService} from '../../core/data/community-data.service';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-create-collection',
|
selector: 'ds-create-community',
|
||||||
styleUrls: ['./create-collection-page.component.scss'],
|
styleUrls: ['./create-community-page.component.scss'],
|
||||||
templateUrl: './create-collection-page.component.html'
|
templateUrl: './create-community-page.component.html'
|
||||||
})
|
})
|
||||||
export class CreateCommunityPageComponent implements OnInit {
|
export class CreateCommunityPageComponent extends CreateComColPageComponent<Collection, NormalizedCollection> {
|
||||||
|
protected frontendURL = 'collections';
|
||||||
public parentUUID$: Observable<string>;
|
|
||||||
public parentRD$: Observable<RemoteData<Community>>;
|
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private communityDataService: CommunityDataService,
|
protected communityDataService: CommunityDataService,
|
||||||
private collectionDataService: CollectionDataService,
|
protected collectionDataService: CollectionDataService,
|
||||||
private routeService: RouteService,
|
protected routeService: RouteService,
|
||||||
private router: Router
|
protected router: Router
|
||||||
) {
|
) {
|
||||||
|
super(collectionDataService, communityDataService, routeService, router);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
|
||||||
this.parentUUID$ = this.routeService.getQueryParameterValue('parent');
|
|
||||||
this.parentUUID$.subscribe((parentID: string) => {
|
|
||||||
if (isNotEmpty(parentID)) {
|
|
||||||
this.parentRD$ = this.communityDataService.findById(parentID);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
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 { RouteService } from '../../shared/services/route.service';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { CreateComColPageComponent } from '../../comcol-forms/create-comcol-page/create-comcol-page.component';
|
import { CreateComColPageComponent } from '../../comcol-forms/create-comcol-page/create-comcol-page.component';
|
||||||
|
import { NormalizedCommunity } from '../../core/cache/models/normalized-community.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-create-community',
|
selector: 'ds-create-community',
|
||||||
styleUrls: ['./create-community-page.component.scss'],
|
styleUrls: ['./create-community-page.component.scss'],
|
||||||
templateUrl: './create-community-page.component.html'
|
templateUrl: './create-community-page.component.html'
|
||||||
})
|
})
|
||||||
export class CreateCommunityPageComponent extends CreateComColPageComponent<Community> {
|
export class CreateCommunityPageComponent extends CreateComColPageComponent<Community, NormalizedCommunity> {
|
||||||
|
protected frontendURL = 'communities';
|
||||||
public constructor(
|
public constructor(
|
||||||
protected communityDataService: CommunityDataService,
|
protected communityDataService: CommunityDataService,
|
||||||
protected routeService: RouteService,
|
protected routeService: RouteService,
|
||||||
|
@@ -10,20 +10,21 @@ import { take } from 'rxjs/operators';
|
|||||||
import { getSucceededRemoteData } from '../../core/shared/operators';
|
import { getSucceededRemoteData } from '../../core/shared/operators';
|
||||||
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
||||||
import { DataService } from '../../core/data/data.service';
|
import { DataService } from '../../core/data/data.service';
|
||||||
|
import { NormalizedDSpaceObject } from '../../core/cache/models/normalized-dspace-object.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-create-community',
|
selector: 'ds-create-community',
|
||||||
styleUrls: ['./create-community-page.component.scss'],
|
styleUrls: ['./create-community-page.component.scss'],
|
||||||
templateUrl: './create-community-page.component.html'
|
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;
|
protected frontendURL: string;
|
||||||
public parentUUID$: Observable<string>;
|
public parentUUID$: Observable<string>;
|
||||||
public parentRD$: Observable<RemoteData<T>>;
|
public parentRD$: Observable<RemoteData<Community>>;
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
protected dsoDataService: DataService<T>,
|
protected dsoDataService: DataService<TNormalized, TDomain>,
|
||||||
protected parentoDataService: CommunityDataService,
|
protected parentDataService: CommunityDataService,
|
||||||
protected routeService: RouteService,
|
protected routeService: RouteService,
|
||||||
protected router: Router
|
protected router: Router
|
||||||
) {
|
) {
|
||||||
@@ -34,19 +35,19 @@ export class CreateComColPageComponent<T extends DSpaceObject> implements OnInit
|
|||||||
this.parentUUID$ = this.routeService.getQueryParameterValue('parent');
|
this.parentUUID$ = this.routeService.getQueryParameterValue('parent');
|
||||||
this.parentUUID$.subscribe((parentID: string) => {
|
this.parentUUID$.subscribe((parentID: string) => {
|
||||||
if (isNotEmpty(parentID)) {
|
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.parentUUID$.pipe(take(1)).subscribe((uuid: string) => {
|
||||||
this.dsoDataService.create(dso, uuid)
|
this.dsoDataService.create(dso, uuid)
|
||||||
.pipe(getSucceededRemoteData())
|
.pipe(getSucceededRemoteData())
|
||||||
.subscribe((dsoRD: RemoteData<Community>) => {
|
.subscribe((dsoRD: RemoteData<TDomain>) => {
|
||||||
if (isNotUndefined(dsoRD)) {
|
if (isNotUndefined(dsoRD)) {
|
||||||
const newUUID = dsoRD.payload.uuid;
|
const newUUID = dsoRD.payload.uuid;
|
||||||
this.router.navigate([frontendURL + newUUID]);
|
this.router.navigate([this.frontendURL + newUUID]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -0,0 +1,45 @@
|
|||||||
|
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]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user