Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix small bugs for dashboard #11569

Merged
merged 4 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,22 @@ export class CreateFactoryCtrl {
if (!factoryContent) {
return;
}
if (this.name) {
// try to set factory name
try {
let factoryObject = angular.fromJson(factoryContent);

try {
let factoryObject = angular.fromJson(factoryContent);
if (this.name) {
// try to set factory name
factoryObject.name = this.name;
factoryContent = angular.toJson(factoryObject);
} catch (e) {
this.$log.error(e);
}
let projects: Array<che.IProject> = factoryObject.workspace.projects || [];
projects.forEach((project: che.IProject) => {
if (!project.type) {
project.type = 'blank'
}
});
factoryContent = angular.toJson(factoryObject);
} catch (e) {
this.$log.error(e);
}

this.isImporting = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export class ImportGitProjectService implements IEditingProgress {
*/
getProjectProps(): che.IProjectTemplate {
const props = {} as che.IProjectTemplate;
const [ , name] = /.*\/([^.]+)(\.git?|$)/i.exec(this._location);
const regExpExecArray = /.*\/([^\/]+?)(?:.git)?$/i.exec(this._location);
const name = angular.isArray(regExpExecArray) && regExpExecArray.length > 1 ? regExpExecArray[1] : 'new-project';
const path = '/' + name.replace(/[^\w-_]/g, '_');
props.name = name;
props.displayName = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export class EditMachineDialogController {
private machineName: string;
private usedMachinesNames: Array<string>;
private environment: che.IWorkspaceEnvironment;
private copyEnvironment: che.IWorkspaceEnvironment;
private previousStateEnvironment: che.IWorkspaceEnvironment;
private currentStateEnvironment: che.IWorkspaceEnvironment;
private originEnvironment: che.IWorkspaceEnvironment;
private editorMode: string;
private isEditorReadOnly: boolean;

Expand All @@ -65,30 +67,34 @@ export class EditMachineDialogController {
this.cheRecipeService = cheRecipeService;

this.isAdd = angular.isUndefined(this.machineName);
this.copyEnvironment = angular.copy(this.environment);
if (!this.copyEnvironment) {
if (!this.environment) {
return;
}
this.usedMachinesNames = Object.keys(this.copyEnvironment.machines).filter((machineName: string) => {
this.originEnvironment = angular.copy(this.environment);
this.deepFreeze(this.originEnvironment);
this.previousStateEnvironment = angular.copy(this.originEnvironment);
this.currentStateEnvironment = angular.copy(this.originEnvironment);

this.usedMachinesNames = Object.keys(this.currentStateEnvironment.machines).filter((machineName: string) => {
return this.isAdd || machineName !== this.machineName;
});

this.environmentManager = this.cheEnvironmentRegistry.getEnvironmentManager(cheRecipeService.getRecipeType(this.copyEnvironment.recipe));
this.environmentManager = this.cheEnvironmentRegistry.getEnvironmentManager(cheRecipeService.getRecipeType(this.currentStateEnvironment.recipe));
if (!this.environmentManager) {
return;
}
this.isEditorReadOnly = CheRecipeTypes.getValues().indexOf(this.environmentManager.type) === -1;
this.editorMode = this.environmentManager.editorMode;

if (this.isAdd) {
if (!cheRecipeService.isScalable(this.copyEnvironment.recipe)) {
if (!cheRecipeService.isScalable(this.currentStateEnvironment.recipe)) {
// we can add a new machine in case with scalable type of recipes only
return;
}
this.machine = this.environmentManager.createMachine(this.copyEnvironment);
this.copyEnvironment = this.environmentManager.addMachine(this.copyEnvironment, this.machine);
this.machine = this.environmentManager.createMachine(this.currentStateEnvironment);
this.currentStateEnvironment = this.environmentManager.addMachine(this.currentStateEnvironment, this.machine);
} else {
const machines = this.environmentManager.getMachines(this.copyEnvironment);
const machines = this.environmentManager.getMachines(this.currentStateEnvironment);
this.machine = angular.copy(machines.find((machine: IEnvironmentManagerMachine) => {
return machine.name === this.machineName;
}));
Expand Down Expand Up @@ -116,10 +122,10 @@ export class EditMachineDialogController {
}
this.environmentManager.setMemoryLimit(this.machine, this.machineRAM);
// update environment's machines
const machines = this.environmentManager.getMachines(this.copyEnvironment).map((machine: IEnvironmentManagerMachine) => {
const machines = this.environmentManager.getMachines(this.currentStateEnvironment).map((machine: IEnvironmentManagerMachine) => {
return machine.name === this.machine.name ? this.machine : machine;
});
this.copyEnvironment = this.environmentManager.getEnvironment(this.copyEnvironment, machines);
this.currentStateEnvironment = this.environmentManager.getEnvironment(this.currentStateEnvironment, machines);
this.stringifyMachineRecipe();
}

Expand Down Expand Up @@ -149,7 +155,7 @@ export class EditMachineDialogController {
const oldMachineName = this.isAdd ? this.machine.name : this.machineName;
this.machineName = name;
const machineName = this.getFullName(name);
const oldEnvironment = this.isAdd ? this.copyEnvironment : this.environment;
const oldEnvironment = this.isAdd ? this.currentStateEnvironment : this.previousStateEnvironment;
const environment = this.environmentManager.renameMachine(oldEnvironment, oldMachineName, machineName);
const machines = this.environmentManager.getMachines(environment);
const machineIndex = machines.findIndex((machine: IEnvironmentManagerMachine) => {
Expand All @@ -159,7 +165,7 @@ export class EditMachineDialogController {
return;
}
this.machine.recipe = machines[machineIndex].recipe;
this.copyEnvironment = this.environmentManager.getEnvironment(environment, machines);
this.currentStateEnvironment = this.environmentManager.getEnvironment(environment, machines);
this.stringifyMachineRecipe();
}

Expand All @@ -170,7 +176,7 @@ export class EditMachineDialogController {
isRecipeValid(): che.IValidation {
try {
this.machine.recipe = this.environmentManager.parseMachineRecipe(this.machineRecipeScript);
if (this.cheRecipeService.isOpenshift(this.copyEnvironment.recipe)) {
if (this.cheRecipeService.isOpenshift(this.currentStateEnvironment.recipe)) {
const newPod = this.machine.recipe.metadata.name;
const oldPod = this.originMachine.recipe.metadata.name;
if (newPod !== oldPod && this.usedMachinesNames.map((name: string) => {
Expand Down Expand Up @@ -198,6 +204,9 @@ export class EditMachineDialogController {
* It will hide the dialog box.
*/
cancel(): void {
if (angular.isFunction(this.onChange) && !angular.equals(this.previousStateEnvironment, this.originEnvironment)) {
this.onChange(angular.copy(this.originEnvironment));
}
this.$mdDialog.cancel();
}

Expand All @@ -209,7 +218,7 @@ export class EditMachineDialogController {
return;
}
if (angular.isFunction(this.onChange)) {
this.onChange(this.copyEnvironment);
this.onChange(this.currentStateEnvironment);
}
this.$mdDialog.hide();
}
Expand All @@ -230,10 +239,10 @@ export class EditMachineDialogController {
// checks memory limit changes
this.checkMemoryLimitChanges();
// update environment's machines
const machines = this.environmentManager.getMachines(this.copyEnvironment).map((machine: IEnvironmentManagerMachine) => {
const machines = this.environmentManager.getMachines(this.currentStateEnvironment).map((machine: IEnvironmentManagerMachine) => {
return machine.name === this.machine.name ? this.machine : machine;
});
this.copyEnvironment = this.environmentManager.getEnvironment(this.copyEnvironment, machines);
this.currentStateEnvironment = this.environmentManager.getEnvironment(this.currentStateEnvironment, machines);
} catch (e) {
this.$log.error('Cannot stringify machine\'s recipe, error: ', e);
}
Expand Down Expand Up @@ -268,7 +277,7 @@ export class EditMachineDialogController {
*/
private checkMemoryLimitChanges(): void {
// check recipe RAM limit
if (!this.cheRecipeService.isScalable(this.environment.recipe)) {
if (!this.cheRecipeService.isScalable(this.previousStateEnvironment.recipe)) {
this.machineRAM = this.environmentManager.getMemoryLimit(this.machine);
} else {
const copyMachine = angular.copy(this.machine);
Expand All @@ -288,18 +297,18 @@ export class EditMachineDialogController {
* Checks critical recipe changes.
*/
private checkCriticalRecipeChanges(): void {
if (this.cheRecipeService.isOpenshift(this.copyEnvironment.recipe)) {
if (this.cheRecipeService.isOpenshift(this.currentStateEnvironment.recipe)) {
// check critical changes for openshift
if (this.isAdd) {
this.copyEnvironment = angular.copy(this.environment);
this.copyEnvironment = this.environmentManager.addMachine(this.copyEnvironment, this.machine);
this.currentStateEnvironment = angular.copy(this.previousStateEnvironment);
this.currentStateEnvironment = this.environmentManager.addMachine(this.currentStateEnvironment, this.machine);
} else {
if (!angular.equals(this.getOpenshiftMachinePod(this.originMachine.recipe), this.getOpenshiftMachinePod(this.machine.recipe))) {
this.copyEnvironment = angular.copy(this.environment);
this.copyEnvironment = this.environmentManager.deleteMachine(this.copyEnvironment, this.originMachine.name);
this.copyEnvironment = this.environmentManager.addMachine(this.copyEnvironment, this.machine);
this.currentStateEnvironment = angular.copy(this.previousStateEnvironment);
this.currentStateEnvironment = this.environmentManager.deleteMachine(this.currentStateEnvironment, this.originMachine.name);
this.currentStateEnvironment = this.environmentManager.addMachine(this.currentStateEnvironment, this.machine);
const name = this.environmentManager.getMachineName(this.machine);
if (!this.copyEnvironment.machines[this.getFullName(name)]) {
if (!this.currentStateEnvironment.machines[this.getFullName(name)]) {
this.onNameChange(name);
}
}
Expand All @@ -313,7 +322,7 @@ export class EditMachineDialogController {
* @returns {IPodItem}
*/
private getOpenshiftMachinePod(machineRecipe: IPodItem): IPodItem {
if (!machineRecipe || this.cheRecipeService.isOpenshift(this.environment.recipe) || !machineRecipe.metadata) {
if (!machineRecipe || this.cheRecipeService.isOpenshift(this.previousStateEnvironment.recipe) || !machineRecipe.metadata) {
return machineRecipe;
}
const pod = angular.copy(machineRecipe);
Expand All @@ -329,4 +338,20 @@ export class EditMachineDialogController {
});
return pod;
}

/**
* Recursively freeze each property which is of type object.
* @param {Object} object
* @returns {Object}
*/
private deepFreeze(object: Object): Object {
Object.getOwnPropertyNames(object).forEach((name: string) => {
if (name.startsWith('__')){
return;
}
let value = object[name];
object[name] = value && typeof value === 'object' ? this.deepFreeze(value) : value;
});
return Object.freeze(object);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export class WorkspaceMachinesController {
machineName: machineName,
environment: this.environment,
onChange: (environment: che.IWorkspaceEnvironment) => {
this.environment = environment;
this.workspaceDetails.config.environments[this.workspaceDetails.config.defaultEnv] = environment;
this.updateData(this.workspaceDetails);
if (angular.isFunction(this.onChange)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
required
ng-minlength="3"
ng-maxlength="100"
ng-pattern="/^[A-Za-z0-9_\-\.]+$/"
ng-pattern="/^[A-Za-z0-9]{1}[A-Za-z0-9_\-\.]+[A-Za-z0-9]{1}$/"
custom-validator="workspaceDetailsOverviewController.isNameUnique($value)">
<che-error-messages che-message-scope="workspace-details-settings" che-message-name="Workspace name">
<div ng-message="pattern">The name should not contain special characters like space, dollar, etc.</div>
<div ng-message="maxlength">The name has to be less than 101 characters long.</div>
<div ng-message="minlength">The name has to be more than 3 characters long.</div>
<div ng-message="pattern">The name should not contain special characters like space, dollar, etc.</div>
<div ng-message="customValidator">This workspace name is already used.</div>
</che-error-messages>
</che-input-box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export interface IDockerimage {
export class DockerimageParser implements IParser {

parse(content: string): IDockerimage {
if (angular.isUndefined(content)) {
throw new TypeError(`Docker image shouldn't be undefined.`);
}

content = content.trim();

if (/\s/.test(content)) {
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/components/typings/che.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ declare namespace che {

export interface IProject {
name: string;
type?: string;
source: IProjectSource;
workspaceId?: string;
workspaceName?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ describe(`cheEditModeOverlay >`, () => {
expect($scope.config.applyButton.action).not.toHaveBeenCalled();
});

it(`shouldn't call a callback when 'cancelButton' is clicked >`, () => {
cancelButtonEl.click();
expect($scope.config.cancelButton.action).not.toHaveBeenCalled();
});

});

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class CheEditModeOverlay implements ng.IDirective {
<che-button-cancel-flat che-button-title="{{config.cancelButton.title || 'Cancel'}}"
name="{{config.cancelButton.name || 'cancel-button'}}"
class="cancel-button"
ng-disabled="config.disabled || config.cancelButton.disabled"
ng-disabled="config.cancelButton.disabled"
ng-click="config.cancelButton.action()"></che-button-cancel-flat>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class CheEditorController {
}

this.editorForm.$setValidity('custom-validator', this.editorState.isValid, null);
}, 1500);
}, 2500);
});
}
};
Expand Down