Skip to content

Commit

Permalink
Disable autosave on Devfile editor page (#14913)
Browse files Browse the repository at this point in the history
* Remove autosave on Devfile editor page

Signed-off-by: Oleksii Kurinnyi <okurinny@redhat.com>

* update ConfirmDialogService

Dialog window can have now only one button.

Signed-off-by: Oleksii Kurinnyi <okurinny@redhat.com>

* fix applying changes to running workspace

Signed-off-by: Oleksii Kurinnyi <okurinny@redhat.com>
  • Loading branch information
akurinnoy authored Oct 29, 2019
1 parent 36bbe35 commit fb2704e
Show file tree
Hide file tree
Showing 39 changed files with 707 additions and 438 deletions.
4 changes: 2 additions & 2 deletions src/app/admin/user-management/user-management.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class AdminsUserManagementCtrl {
*/
removeUser(event: MouseEvent, user: any): void {
let content = 'Are you sure you want to remove \'' + user.email + '\'?';
let promise = this.confirmDialogService.showConfirmDialog('Remove user', content, 'Delete', 'Cancel');
let promise = this.confirmDialogService.showConfirmDialog('Remove user', content, { resolve: 'Delete', reject: 'Cancel' });

promise.then(() => {
this.isLoading = true;
Expand Down Expand Up @@ -231,7 +231,7 @@ export class AdminsUserManagementCtrl {
content += 'user?';
}

return this.confirmDialogService.showConfirmDialog('Remove users', content, 'Delete', 'Cancel');
return this.confirmDialogService.showConfirmDialog('Remove users', content, { resolve: 'Delete', reject: 'Cancel' });
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class DockerRegistryListController {
} else {
content += 'this selected registry?';
}
return this.confirmDialogService.showConfirmDialog('Remove registries', content, 'Delete');
return this.confirmDialogService.showConfirmDialog('Remove registries', content, { resolve: 'Delete' });
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class FactoryInformationController {

const title = 'Warning',
content = `You have unsaved changes in JSON configuration. Would you like to save changes now?`;
return this.confirmDialogService.showConfirmDialog(title, content, 'Continue').then(() => {
return this.confirmDialogService.showConfirmDialog(title, content, { resolve: 'Continue' }).then(() => {
this.updateFactoryContent();
});
}
Expand Down Expand Up @@ -296,7 +296,7 @@ export class FactoryInformationController {
*/
deleteFactory(): void {
let content = 'Please confirm removal for the factory \'' + (this.factory.name ? this.factory.name : this.factory.id) + '\'.';
let promise = this.confirmDialogService.showConfirmDialog('Remove the factory', content, 'Delete');
let promise = this.confirmDialogService.showConfirmDialog('Remove the factory', content, { resolve: 'Delete' });

promise.then(() => {
// remove it !
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,6 @@ export class ListFactoriesController {
} else {
content += 'this selected factory?';
}
return this.confirmDialogService.showConfirmDialog('Remove factories', content, 'Delete');
return this.confirmDialogService.showConfirmDialog('Remove factories', content, { resolve: 'Delete' });
}
}
66 changes: 51 additions & 15 deletions src/app/navbar/recent-workspaces/recent-workspaces.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
* Red Hat, Inc. - initial API and implementation
*/
'use strict';
import {CheWorkspace} from '../../../components/api/workspace/che-workspace.factory';
import { CheWorkspace } from '../../../components/api/workspace/che-workspace.factory';
import IdeSvc from '../../../app/ide/ide.service';
import {CheBranding} from '../../../components/branding/che-branding.factory';
import {WorkspacesService} from '../../workspaces/workspaces.service';
import {CheNotification} from '../../../components/notification/che-notification.factory';
import { CheBranding } from '../../../components/branding/che-branding.factory';
import { WorkspacesService } from '../../workspaces/workspaces.service';
import { CheNotification } from '../../../components/notification/che-notification.factory';
import { WorkspaceDetailsService } from '../../workspaces/workspace-details/workspace-details.service';


const MAX_RECENT_WORKSPACES_ITEMS: number = 5;
Expand All @@ -27,7 +28,18 @@ const MAX_RECENT_WORKSPACES_ITEMS: number = 5;
*/
export class NavbarRecentWorkspacesController {

static $inject = ['ideSvc', 'cheWorkspace', 'cheBranding', '$window', '$log', '$scope', '$rootScope', 'workspacesService', 'cheNotification'];
static $inject = [
'ideSvc',
'cheWorkspace',
'cheBranding',
'$window',
'$log',
'$scope',
'$rootScope',
'workspacesService',
'cheNotification',
'workspaceDetailsService'
];

cheWorkspace: CheWorkspace;
dropdownItemTempl: Array<any>;
Expand All @@ -45,19 +57,23 @@ export class NavbarRecentWorkspacesController {
workspacesService: WorkspacesService;
cheNotification: CheNotification;
cheBranding: CheBranding;
workspaceDetailsService: WorkspaceDetailsService;

/**
* Default constructor
*/
constructor(ideSvc: IdeSvc,
cheWorkspace: CheWorkspace,
cheBranding: CheBranding,
$window: ng.IWindowService,
$log: ng.ILogService,
$scope: ng.IScope,
$rootScope: ng.IRootScopeService,
workspacesService: WorkspacesService,
cheNotification: CheNotification) {
constructor(
ideSvc: IdeSvc,
cheWorkspace: CheWorkspace,
cheBranding: CheBranding,
$window: ng.IWindowService,
$log: ng.ILogService,
$scope: ng.IScope,
$rootScope: ng.IRootScopeService,
workspacesService: WorkspacesService,
cheNotification: CheNotification,
workspaceDetailsService: WorkspaceDetailsService
) {
this.ideSvc = ideSvc;
this.cheWorkspace = cheWorkspace;
this.$log = $log;
Expand All @@ -66,6 +82,7 @@ export class NavbarRecentWorkspacesController {
this.workspacesService = workspacesService;
this.cheNotification = cheNotification;
this.cheBranding = cheBranding;
this.workspaceDetailsService = workspaceDetailsService;

// workspace updated time map by id
this.workspaceUpdated = new Map();
Expand Down Expand Up @@ -320,6 +337,11 @@ export class NavbarRecentWorkspacesController {
* @param workspaceId {String} workspace id
*/
stopRecentWorkspace(workspaceId: string): void {
if (this.checkUnsavedChanges(workspaceId)) {
this.workspaceDetailsService.notifyUnsavedChangesDialog();
return;
}

this.cheWorkspace.stopWorkspace(workspaceId).then(() => {
angular.noop();
}, (error: any) => {
Expand All @@ -333,11 +355,16 @@ export class NavbarRecentWorkspacesController {
* @param workspaceId {String} workspace id
*/
runRecentWorkspace(workspaceId: string): void {
if (this.checkUnsavedChanges(workspaceId)) {
this.workspaceDetailsService.notifyUnsavedChangesDialog();
return;
}

let workspace = this.cheWorkspace.getWorkspaceById(workspaceId);

this.updateRecentWorkspace(workspaceId);

this.cheWorkspace.startWorkspace(workspace.id, workspace.config ? workspace.config.defaultEnv: null).catch((error: any) => {
this.cheWorkspace.startWorkspace(workspace.id, workspace.config ? workspace.config.defaultEnv : null).catch((error: any) => {
this.$log.error(error);
this.cheNotification.showError('Run workspace error.', error);
});
Expand All @@ -352,4 +379,13 @@ export class NavbarRecentWorkspacesController {
updateRecentWorkspace(workspaceId: string): void {
this.$rootScope.$broadcast('recent-workspace:set', workspaceId);
}

/**
* Returns `true` if workspace configuration has unsaved changes.
* @param id a workspace ID
*/
checkUnsavedChanges(id: string): ng.IPromise<any> | any {
return this.workspaceDetailsService.isWorkspaceConfigSaved(id) === false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export class ListOrganizationsController {
content += 'this selected organization?';
}

return this.confirmDialogService.showConfirmDialog('Delete organizations', content, 'Delete');
return this.confirmDialogService.showConfirmDialog('Delete organizations', content, { resolve: 'Delete' });
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ export class OrganizationsItemController {
*/
confirmRemoval(): ng.IPromise<any> {
return this.confirmDialogService.showConfirmDialog('Delete organization',
'Would you like to delete organization \'' + this.organization.name + '\'?', 'Delete');
'Would you like to delete organization \'' + this.organization.name + '\'?', { resolve: 'Delete' });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export class OrganizationDetailsController {
*/
deleteOrganization(): void {
let promise = this.confirmDialogService.showConfirmDialog('Delete organization',
'Would you like to delete organization \'' + this.organization.name + '\'?', 'Delete');
'Would you like to delete organization \'' + this.organization.name + '\'?', { resolve: 'Delete' });

promise.then(() => {
let promise = this.cheOrganization.deleteOrganization(this.organization.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export class ListOrganizationMembersController {
* @param member
*/
removeMember(member: che.IMember): void {
let promise = this.confirmDialogService.showConfirmDialog('Remove member', 'Would you like to remove member ' + member.email + ' ?', 'Delete');
let promise = this.confirmDialogService.showConfirmDialog('Remove member', 'Would you like to remove member ' + member.email + ' ?', { resolve: 'Delete' });

promise.then(() => {
this.removePermissions(member);
Expand Down Expand Up @@ -507,6 +507,6 @@ export class ListOrganizationMembersController {
confirmTitle += 'the selected member?';
}

return this.confirmDialogService.showConfirmDialog('Remove members', confirmTitle, 'Delete');
return this.confirmDialogService.showConfirmDialog('Remove members', confirmTitle, { resolve: 'Delete' });
}
}
2 changes: 1 addition & 1 deletion src/app/teams/list/list-teams.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,6 @@ export class ListTeamsController {
content += 'this selected team?';
}

return this.confirmDialogService.showConfirmDialog('Delete teams', content, 'Delete');
return this.confirmDialogService.showConfirmDialog('Delete teams', content, { resolve: 'Delete' });
}
}
2 changes: 1 addition & 1 deletion src/app/teams/list/team-item/team-item.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class TeamItemController {
*/
confirmRemoval(): ng.IPromise<any> {
let promise = this.confirmDialogService.showConfirmDialog('Delete team',
'Would you like to delete team \'' + this.team.name + '\'?', 'Delete');
'Would you like to delete team \'' + this.team.name + '\'?', { resolve: 'Delete' });
return promise;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/teams/team-details/team-details.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ tab: Object = Tab;
*/
deleteTeam(event: MouseEvent): void {
let promise = this.confirmDialogService.showConfirmDialog('Delete team',
'Would you like to delete team \'' + this.team.name + '\'?', 'Delete');
'Would you like to delete team \'' + this.team.name + '\'?', { resolve: 'Delete' });

promise.then(() => {
let promise = this.cheTeam.deleteTeam(this.team.id);
Expand All @@ -334,7 +334,7 @@ tab: Object = Tab;
*/
leaveTeam(): void {
let promise = this.confirmDialogService.showConfirmDialog('Leave team',
'Would you like to leave team \'' + this.team.name + '\'?', 'Leave');
'Would you like to leave team \'' + this.team.name + '\'?', { resolve: 'Leave' });

promise.then(() => {
let promise = this.chePermissions.removeOrganizationPermissions(this.team.id, this.cheUser.getUser().id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,6 @@ export class ListTeamMembersController {
confirmTitle += 'the selected member?';
}

return this.confirmDialogService.showConfirmDialog('Remove members', confirmTitle, 'Delete');
return this.confirmDialogService.showConfirmDialog('Remove members', confirmTitle, { resolve: 'Delete' });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class MemberItemController {
* @param event - the $event
*/
removeMember(event: MouseEvent): void {
let promise = this.confirmDialogService.showConfirmDialog('Remove member', 'Would you like to remove member ' + this.member.email + ' ?', 'Delete');
let promise = this.confirmDialogService.showConfirmDialog('Remove member', 'Would you like to remove member ' + this.member.email + ' ?', { resolve: 'Delete' });

promise.then(() => {
if (this.member.isPending) {
Expand Down
10 changes: 5 additions & 5 deletions src/app/workspaces/create-workspace/create-workspace.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,16 @@ export class CreateWorkspaceSvc {
});

projects.push(template);
});
});

return this.checkEditingProgress().then(() => {
sourceDevfile.projects = projects;

// If no projects defined in devfile were added - remove the commands from devfile as well:
if (noProjectsFromDevfile) {
sourceDevfile.commands = [];
}

return this.cheWorkspace.createWorkspaceFromDevfile(namespaceId, sourceDevfile, attributes).then((workspace: che.IWorkspace) => {
return this.cheWorkspace.fetchWorkspaces().then(() => this.cheWorkspace.getWorkspaceById(workspace.id));
})
Expand Down Expand Up @@ -246,7 +246,7 @@ export class CreateWorkspaceSvc {

const title = 'Warning',
content = `You have project editing, that is not completed. Would you like to proceed to workspace creation without these changes?`;
return this.confirmDialogService.showConfirmDialog(title, content, 'Continue');
return this.confirmDialogService.showConfirmDialog(title, content, { resolve: 'Continue' });
}

/**
Expand Down Expand Up @@ -289,7 +289,7 @@ export class CreateWorkspaceSvc {

/**
* Returns name of the pointed workspace.
*
*
* @param workspace workspace
*/
getWorkspaceName(workspace: che.IWorkspace): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export class ListWorkspacesCtrl {
content += 'this selected workspace?';
}

return this.confirmDialogService.showConfirmDialog('Remove workspaces', content, 'Delete');
return this.confirmDialogService.showConfirmDialog('Remove workspaces', content, { resolve: 'Delete' });
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export class ShareWorkspaceController {
content += 'this selected member?';
}

return this.confirmDialogService.showConfirmDialog('Remove members', content, 'Delete');
return this.confirmDialogService.showConfirmDialog('Remove members', content, { resolve: 'Delete' });
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class UserItemController {
*/
removeUser(): void {
let content = 'Please confirm removal for the member \'' + this.user.email + '\'.';
let promise = this.confirmDialogService.showConfirmDialog('Remove the member', content, 'Delete');
let promise = this.confirmDialogService.showConfirmDialog('Remove the member', content, { resolve: 'Delete' });

promise.then(() => {
// callback is set in scope definition:
Expand Down
Loading

0 comments on commit fb2704e

Please sign in to comment.