-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
344 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/app/item-page/edit-item-page/item-clone/item-clone.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<h1>{{'item.edit.clone.head' | translate: {id: (itemRD$ | async)?.payload?.handle} }}</h1> | ||
<p>{{'item.edit.clone.description' | translate}}</p> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<div class="card mb-3"> | ||
<div class="card-header">{{'dso-selector.placeholder' | translate: { type: 'dso-selector.placeholder.type.collection' | translate } }}</div> | ||
<div class="card-body"> | ||
<ds-authorized-collection-selector [types]="COLLECTIONS" | ||
[entityType]="item.getRenderTypes[0]" | ||
[currentDSOId]="selectedCollection ? selectedCollection.id : originalCollection.id" | ||
(onSelect)="selectDso($event)"> | ||
</ds-authorized-collection-selector> | ||
</div> | ||
<div></div> | ||
</div> | ||
</div> | ||
</div> | ||
<!--<div class="row"> | ||
<div class="col-12"> | ||
<p> | ||
<label for="inheritPoliciesCheckbox"> | ||
<ng-template #tooltipContent> | ||
{{ 'item.edit.clone.inheritpolicies.tooltip' | translate }} | ||
</ng-template> | ||
<input type="checkbox" name="tc" [(ngModel)]="inheritPolicies" id="inheritPoliciesCheckbox" [ngbTooltip]="tooltipContent" | ||
> | ||
{{'item.edit.clone.inheritpolicies.checkbox' |translate}} | ||
</label> | ||
</p> | ||
<p> | ||
{{'item.edit.clone.inheritpolicies.description' | translate}} | ||
</p> | ||
</div> | ||
</div>--> | ||
|
||
<div class="button-row bottom"> | ||
<div class="float-right space-children-mr"> | ||
<button [routerLink]="[(itemPageRoute$ | async), 'edit']" class="btn btn-outline-secondary"> | ||
<i class="fas fa-arrow-left"></i> {{'item.edit.clone.cancel' | translate}} | ||
</button> | ||
<button class="btn btn-primary" [disabled]="!canClone" (click)="cloneToCollection()"> | ||
<span *ngIf="!processing"> | ||
<i class="fas fa-save"></i> {{'item.edit.clone.save-button' | translate}} | ||
</span> | ||
<span *ngIf="processing"> | ||
<i class="fas fa-circle-notch fa-spin"></i> {{'item.edit.clone.processing' | translate}} | ||
</span> | ||
</button> | ||
<button class="btn btn-danger" [disabled]="!canSubmit" (click)="discard()"> | ||
<i class="fas fa-times"></i> {{"item.edit.clone.discard-button" | translate}} | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
175 changes: 175 additions & 0 deletions
175
src/app/item-page/edit-item-page/item-clone/item-clone.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
import { | ||
AsyncPipe, | ||
NgIf, | ||
} from '@angular/common'; | ||
import { | ||
Component, | ||
OnInit, | ||
} from '@angular/core'; | ||
import { | ||
FormsModule, | ||
ReactiveFormsModule, | ||
} from '@angular/forms'; | ||
import { | ||
ActivatedRoute, | ||
Router, | ||
RouterLink, | ||
} from '@angular/router'; | ||
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { | ||
TranslateModule, | ||
TranslateService, | ||
} from '@ngx-translate/core'; | ||
import { Observable } from 'rxjs'; | ||
import { | ||
map, | ||
switchMap, | ||
} from 'rxjs/operators'; | ||
|
||
import { DSONameService } from '../../../core/breadcrumbs/dso-name.service'; | ||
import { ItemDataService } from '../../../core/data/item-data.service'; | ||
import { RemoteData } from '../../../core/data/remote-data'; | ||
import { RequestService } from '../../../core/data/request.service'; | ||
import { Collection } from '../../../core/shared/collection.model'; | ||
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model'; | ||
import { Item } from '../../../core/shared/item.model'; | ||
import { | ||
getAllSucceededRemoteDataPayload, | ||
getFirstCompletedRemoteData, | ||
getFirstSucceededRemoteData, | ||
getFirstSucceededRemoteDataPayload, | ||
getRemoteDataPayload, | ||
} from '../../../core/shared/operators'; | ||
import { SearchService } from '../../../core/shared/search/search.service'; | ||
import { WorkspaceItem } from '../../../core/submission/models/workspaceitem.model'; | ||
import { WorkspaceitemDataService } from '../../../core/submission/workspaceitem-data.service'; | ||
import { AuthorizedCollectionSelectorComponent } from '../../../shared/dso-selector/dso-selector/authorized-collection-selector/authorized-collection-selector.component'; | ||
import { NotificationsService } from '../../../shared/notifications/notifications.service'; | ||
import { getItemPageRoute } from '../../item-page-routing-paths'; | ||
|
||
@Component({ | ||
selector: 'ds-item-clone', | ||
templateUrl: './item-clone.component.html', | ||
imports: [ | ||
AsyncPipe, | ||
AuthorizedCollectionSelectorComponent, | ||
NgIf, | ||
ReactiveFormsModule, | ||
TranslateModule, | ||
FormsModule, | ||
NgbTooltipModule, | ||
RouterLink, | ||
], | ||
standalone: true, | ||
}) | ||
export class ItemCloneComponent implements OnInit { | ||
/** | ||
* TODO: Similarly to {@code ItemMoveComponent}, there is currently no backend support to change the | ||
* owningCollection and inherit policies, hence the code that was commented out | ||
*/ | ||
|
||
selectorType = DSpaceObjectType.COLLECTION; | ||
|
||
inheritPolicies = false; | ||
itemRD$: Observable<RemoteData<Item>>; | ||
originalCollection: Collection; | ||
|
||
selectedCollectionName: string; | ||
selectedCollection: Collection; | ||
canSubmit = false; | ||
|
||
item: Item; | ||
processing = false; | ||
|
||
/** | ||
* Route to the item's page | ||
*/ | ||
itemPageRoute$: Observable<string>; | ||
|
||
COLLECTIONS = [DSpaceObjectType.COLLECTION]; | ||
|
||
constructor(private route: ActivatedRoute, | ||
private router: Router, | ||
private notificationsService: NotificationsService, | ||
private itemDataService: ItemDataService, | ||
private workspaceItemDataService: WorkspaceitemDataService, | ||
private searchService: SearchService, | ||
private translateService: TranslateService, | ||
private requestService: RequestService, | ||
protected dsoNameService: DSONameService, | ||
) {} | ||
|
||
ngOnInit(): void { | ||
this.itemRD$ = this.route.data.pipe( | ||
map((data) => data.dso), getFirstSucceededRemoteData(), | ||
) as Observable<RemoteData<Item>>; | ||
this.itemPageRoute$ = this.itemRD$.pipe( | ||
getAllSucceededRemoteDataPayload(), | ||
map((item) => getItemPageRoute(item)), | ||
); | ||
this.itemRD$.subscribe((rd) => { | ||
this.item = rd.payload; | ||
}, | ||
); | ||
this.itemRD$.pipe( | ||
getFirstSucceededRemoteData(), | ||
getRemoteDataPayload(), | ||
switchMap((item) => item.owningCollection), | ||
getFirstSucceededRemoteData(), | ||
getRemoteDataPayload(), | ||
).subscribe((collection) => { | ||
this.originalCollection = collection; | ||
}); | ||
} | ||
|
||
/** | ||
* Set the collection name and id based on the selected value | ||
* @param data - obtained from the ds-input-suggestions component | ||
*/ | ||
selectDso(data: any): void { | ||
this.selectedCollection = data; | ||
this.selectedCollectionName = this.dsoNameService.getName(data); | ||
this.canSubmit = true; | ||
} | ||
|
||
/** | ||
* @returns {string} the current URL | ||
*/ | ||
getCurrentUrl() { | ||
return this.router.url; | ||
} | ||
|
||
/** | ||
* Moves the item to a new collection based on the selected collection | ||
*/ | ||
cloneToCollection() { | ||
this.processing = true; | ||
const clone$ = this.workspaceItemDataService.cloneToCollection(this.item._links.self.href, this.selectedCollection.id) | ||
.pipe(getFirstCompletedRemoteData()); | ||
|
||
clone$.subscribe((response: RemoteData<any>) => { | ||
if (response.hasSucceeded) { | ||
this.notificationsService.success(this.translateService.get('item.edit.clone.success')); | ||
} else { | ||
this.notificationsService.error(this.translateService.get('item.edit.clone.error')); | ||
} | ||
}); | ||
|
||
clone$.pipe( | ||
getFirstSucceededRemoteDataPayload<WorkspaceItem>()) | ||
.subscribe((wsi) => { | ||
this.processing = false; | ||
this.router.navigate(['/workspaceitems', wsi.id, 'edit']); | ||
}); | ||
|
||
} | ||
|
||
discard(): void { | ||
this.selectedCollection = null; | ||
this.canSubmit = false; | ||
} | ||
|
||
get canClone(): boolean { | ||
return this.canSubmit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.