mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-22 08:38:03 +01:00
Merge pull request #4187 from ninjadq/leaving_repo_dialog
Fix open confirmation dialog when leving repo
This commit is contained in:
commit
11288ccc0c
@ -52,6 +52,7 @@ import { MemberGuard } from './shared/route/member-guard-activate.service';
|
||||
import { TagDetailPageComponent } from './repository/tag-detail/tag-detail-page.component';
|
||||
import { ReplicationRuleComponent} from "./replication/replication-rule/replication-rule.component";
|
||||
import {LeavingNewRuleRouteDeactivate} from "./shared/route/leaving-new-rule-deactivate.service";
|
||||
import { LeavingRepositoryRouteDeactivate } from './shared/route/leaving-repository-deactivate.service';
|
||||
|
||||
const harborRoutes: Routes = [
|
||||
{ path: '', redirectTo: 'harbor', pathMatch: 'full' },
|
||||
@ -117,6 +118,7 @@ const harborRoutes: Routes = [
|
||||
path: 'projects/:id/repositories/:repo',
|
||||
component: TagRepositoryComponent,
|
||||
canActivate: [MemberGuard],
|
||||
canDeactivate: [LeavingRepositoryRouteDeactivate],
|
||||
resolve: {
|
||||
projectResolver: ProjectRoutingResolver
|
||||
}
|
||||
|
@ -154,7 +154,6 @@ export class MemberComponent implements OnInit, OnDestroy {
|
||||
initBatchMessage.name = data.username;
|
||||
this.batchActionInfos.push(initBatchMessage);
|
||||
});
|
||||
this.OperateDialogService.addBatchInfoList(this.batchActionInfos);
|
||||
|
||||
this.changeOpe(m);
|
||||
}
|
||||
|
@ -11,12 +11,14 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
// import { RepositoryComponent} from 'harbor-ui';
|
||||
import { AppConfigService } from '../../app-config.service';
|
||||
import { SessionService } from '../../shared/session.service';
|
||||
import { TagClickEvent } from 'harbor-ui';
|
||||
import { Project } from '../../project/project';
|
||||
import { RepositoryComponent } from 'harbor-ui/src/repository/repository.component';
|
||||
|
||||
@Component({
|
||||
selector: 'tag-repository',
|
||||
@ -30,6 +32,9 @@ export class TagRepositoryComponent implements OnInit {
|
||||
hasProjectAdminRole: boolean = false;
|
||||
registryUrl: string;
|
||||
|
||||
@ViewChild(RepositoryComponent)
|
||||
repositoryComponent: RepositoryComponent;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
@ -65,6 +70,9 @@ export class TagRepositoryComponent implements OnInit {
|
||||
return this.session.getCurrentUser() !== null;
|
||||
}
|
||||
|
||||
hasChanges(): boolean {
|
||||
return this.repositoryComponent.hasChanges();
|
||||
}
|
||||
watchTagClickEvt(tagEvt: TagClickEvent): void {
|
||||
let linkUrl = ['harbor', 'projects', tagEvt.project_id, 'repositories', tagEvt.repository_name, 'tags', tagEvt.tag_name];
|
||||
this.router.navigate(linkUrl);
|
||||
|
@ -0,0 +1,64 @@
|
||||
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
CanDeactivate, Router,
|
||||
ActivatedRouteSnapshot,
|
||||
RouterStateSnapshot
|
||||
} from '@angular/router';
|
||||
|
||||
import { ConfirmationDialogService } from '../confirmation-dialog/confirmation-dialog.service';
|
||||
|
||||
import { ConfirmationMessage } from '../confirmation-dialog/confirmation-message';
|
||||
import { ConfirmationState, ConfirmationTargets } from '../shared.const';
|
||||
import { TagRepositoryComponent } from '../../repository/tag-repository/tag-repository.component';
|
||||
|
||||
@Injectable()
|
||||
export class LeavingRepositoryRouteDeactivate implements CanDeactivate<TagRepositoryComponent> {
|
||||
constructor(
|
||||
private router: Router,
|
||||
private confirmation: ConfirmationDialogService) { }
|
||||
|
||||
canDeactivate(
|
||||
tagRepo: TagRepositoryComponent,
|
||||
route: ActivatedRouteSnapshot,
|
||||
state: RouterStateSnapshot): Promise<boolean> | boolean {
|
||||
// Confirmation before leaving config route
|
||||
return new Promise((resolve, reject) => {
|
||||
if (tagRepo && tagRepo.hasChanges()) {
|
||||
let msg: ConfirmationMessage = new ConfirmationMessage(
|
||||
"CONFIG.LEAVING_CONFIRMATION_TITLE",
|
||||
"CONFIG.LEAVING_CONFIRMATION_SUMMARY",
|
||||
'',
|
||||
{},
|
||||
ConfirmationTargets.REPOSITORY
|
||||
);
|
||||
this.confirmation.openComfirmDialog(msg);
|
||||
return this.confirmation.confirmationConfirm$.subscribe(msg => {
|
||||
if (msg && msg.source === ConfirmationTargets.REPOSITORY) {
|
||||
if (msg.state === ConfirmationState.CONFIRMED) {
|
||||
return resolve(true);
|
||||
} else {
|
||||
return resolve(false); // Prevent leading route
|
||||
}
|
||||
} else {
|
||||
return resolve(true); // Should go on
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return resolve(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -59,6 +59,7 @@ import {
|
||||
HarborLibraryModule
|
||||
} from 'harbor-ui';
|
||||
import {LeavingNewRuleRouteDeactivate} from "./route/leaving-new-rule-deactivate.service";
|
||||
import { LeavingRepositoryRouteDeactivate } from './route/leaving-repository-deactivate.service';
|
||||
|
||||
const uiLibConfig: IServiceConfig = {
|
||||
enablei18Support: true,
|
||||
@ -125,6 +126,7 @@ const uiLibConfig: IServiceConfig = {
|
||||
SignInGuard,
|
||||
LeavingConfigRouteDeactivate,
|
||||
LeavingNewRuleRouteDeactivate,
|
||||
LeavingRepositoryRouteDeactivate,
|
||||
MemberGuard,
|
||||
MessageHandlerService,
|
||||
StatisticHandler
|
||||
|
Loading…
Reference in New Issue
Block a user