Skip to content

Commit

Permalink
Changes collection URL when the collection is updated (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
garyluu authored Mar 20, 2019
1 parent 6bfa1f0 commit 8ad0532
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/app/organizations/state/collections.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material';
import { Router } from '@angular/router';
import { ID, transaction } from '@datorama/akita';
import { finalize } from 'rxjs/operators';
import { AlertService } from '../../shared/alert/state/alert.service';
Expand All @@ -30,7 +31,7 @@ export class CollectionsService {
constructor(private collectionsStore: CollectionsStore, private organizationsService: OrganizationsService,
private alertService: AlertService, private organizationService: OrganizationService,
private organizationStore: OrganizationQuery, private collectionsQuery: CollectionsQuery,
private matDialog: MatDialog) {
private matDialog: MatDialog, private router: Router) {
}

clearState() {
Expand Down Expand Up @@ -90,6 +91,14 @@ export class CollectionsService {
});
}

/**
* Currently only used from the collection page
* Grabs detailed collection information and navigates to the collection's page
*
* @param {number} organizationId The ID of the organization that the collection belongs to
* @param {number} collectionId The ID of the collection
* @memberof CollectionsService
*/
@transaction()
updateCollectionFromId(organizationId: number, collectionId: number) {
this.collectionsStore.setError(false);
Expand All @@ -101,6 +110,8 @@ export class CollectionsService {
this.collectionsStore.createOrReplace(collection.id, collection);
this.collectionsStore.setActive(collection.id);
this.organizationService.updateOrganizationFromID(collection.organizationID);
// Navigate to the new collectionName in case the name changes.
this.router.navigate(['/organizations', collection.organizationName, 'collections', collection.name]);
}, () => {
this.collectionsStore.setError(true);
});
Expand Down

0 comments on commit 8ad0532

Please sign in to comment.