Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
printing switch states
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Nov 27, 2017
1 parent 4efb4e9 commit b0ff680
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 127 deletions.
2 changes: 2 additions & 0 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4183,6 +4183,8 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable {
deploy_templates.checkOfficialRepositoryVersions
.apply(ME, []);
}

deploy_switch.printSwitchStates.apply(ME, []);
}
finally {
DOES_NOT_RELOAD_CONFIG_ANYMORE();
Expand Down
3 changes: 3 additions & 0 deletions src/i18.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,13 @@ export interface Translation {
defaultName?: string;
defaultOptionName?: string;
description?: string;
item?: string;
noDefined?: string;
noOptionsDefined?: string;
noOptionSelected?: string;
selectOption?: string;
selectSwitch?: string;
states?: string;
},
test?: {
description?: string;
Expand Down
3 changes: 3 additions & 0 deletions src/lang/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,13 @@ export const translation: Translation = {
defaultName: 'Schalter #{0:trim}',
defaultOptionName: 'Schalter-Option #{0:trim}',
description: 'Schaltet zwischen anderen existierenden Zielen um',
item: "{0:trim,surround}: ",
noDefined: 'Es wurden keine Schalter gefunden!',
noOptionsDefined: 'Es wurden keine Optionen für den Schalter {0:trim,surround} definiert!',
noOptionSelected: 'KEINE OPTION AUSGEWÄHLT',
selectOption: 'Wählen Sie eine Option für den Schalter {0:trim,surround}...',
selectSwitch: 'Wählen Sie einen Schalter aus...',
states: 'Schalter-Stati:',
},
test: {
description: 'Ein Test-PlugIn, welches lediglich anzeigt, welche Dateien bereitgestellt würden',
Expand Down
3 changes: 3 additions & 0 deletions src/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,13 @@ export const translation: Translation = {
defaultName: 'Switch #{0:trim}',
defaultOptionName: 'Switch option #{0:trim}',
description: 'Switches between existing targets',
item: "{0:trim,surround}: ",
noDefined: 'No swicthes available!',
noOptionsDefined: 'No options were defined for the switch {0:trim,surround}!',
noOptionSelected: 'NO OPTION SELECTED',
selectOption: 'Select an option for the switch {0:trim,surround}...',
selectSwitch: 'Select a switch...',
states: 'Switch states:',
},
test: {
description: 'A mock deployer that only displays what files would be deployed',
Expand Down
132 changes: 11 additions & 121 deletions src/plugins/switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import * as deploy_switch from '../switch';
import * as deploy_targets from '../targets';
import * as Enumerable from 'node-enumerable';
import * as i18 from '../i18';
import * as vscode from 'vscode';
import * as Workflows from 'node-workflows';


Expand All @@ -53,6 +54,12 @@ export interface DeployTargetSwitchOption extends deploy_contracts.Sortable {
* Gets the ID of that option.
*/
__id?: any;
/**
* [INTERNAL] DO NOT DEFINE OR OVERWRITE THIS PROPERTY BY YOUR OWN!
*
* The zero-based index.
*/
__index?: number;

/**
* The description.
Expand All @@ -78,125 +85,6 @@ export interface DeployTargetSwitchOption extends deploy_contracts.Sortable {
export type DeployTargetSwitchOptionValue = DeployTargetSwitchOption | string;


/**
* Returns the current option of a target.
*
* @param {DeployTargetSwitch} target The target.
* @param {TDefault} [defaultValue] The custom default value.
*
* @return {DeployTargetSwitchOption|TDefault} The option (if found).
*/
export function getCurrentOptionOf<TDefault = false>(target: DeployTargetSwitch,
defaultValue = <TDefault><any>false): DeployTargetSwitchOption | TDefault {
if (!target) {
return <any>target;
}

const TARGET_NAME = deploy_helpers.normalizeString( target.name );

const STATES = deploy_switch.getSelectedSwitchOptions();
if (STATES) {
const OPTION = STATES[TARGET_NAME];
if ('object' === typeof OPTION) {
return OPTION; // found
}
else {
// get first (default) one
// instead

return Enumerable.from(
getTargetOptionsOf(target)
).orderBy(o => {
return deploy_helpers.toBooleanSafe(o.isDefault) ? 0 : 1;
}).firstOrDefault(x => true,
defaultValue);
}
}

return defaultValue;
}



/**
* Returns the options of a switch target.
*
* @param {DeployTargetSwitch} target The target.
*
* @return {DeployTargetSwitchOption[]} The options.
*/
export function getTargetOptionsOf(target: DeployTargetSwitch): DeployTargetSwitchOption[] {
if (deploy_helpers.isNullOrUndefined(target)) {
return <any>target;
}

const TARGET_NAME = deploy_helpers.normalizeString(target.name);

const OPTIONS: DeployTargetSwitchOption[] = [];

let objIndex = -1;
Enumerable.from( deploy_helpers.asArray(target.options) ).where(v => {
return !deploy_helpers.isNullOrUndefined(v);
}).select(v => {
++objIndex;

v = deploy_helpers.cloneObject(v);

if ('object' !== typeof v) {
v = {
targets: [ deploy_helpers.normalizeString(v) ]
};
}

v.__id = `${target.__id}\n` +
`${deploy_helpers.normalizeString(deploy_helpers.getSortValue(v))}\n` +
`${objIndex}\n` +
`${deploy_helpers.normalizeString(v.name)}`;

v.targets = Enumerable.from( deploy_helpers.asArray(v.targets) ).select(t => {
return deploy_helpers.normalizeString(t);
}).where(t => '' !== t &&
TARGET_NAME !== t)
.distinct()
.toArray();

return v;
})
.pushTo(OPTIONS);

return OPTIONS.sort((x, y) => {
return deploy_helpers.compareValuesBy(x, y,
o => deploy_helpers.getSortValue(o));
});
}

/**
* Sets the current option for a switch target.
*
* @param {DeployTargetSwitch} target The target.
* @param {DeployTargetSwitchOption} option The option to set.
*
* @return {Object} The new data.
*/
export function setCurrentOptionFor(target: DeployTargetSwitch, option: DeployTargetSwitchOption): { option: DeployTargetSwitchOption, target: DeployTargetSwitch } {
if (!target) {
return <any>target;
}

const NAME = deploy_helpers.normalizeString( target.name );

const STATES = deploy_switch.getSelectedSwitchOptions();
if (STATES) {
STATES[NAME] = option;

return {
option: STATES[NAME],
target: target,
};
}
}


class SwitchPlugin extends deploy_objects.MultiFileDeployPluginBase {
public get canGetFileInfo(): boolean {
return true;
Expand Down Expand Up @@ -537,9 +425,11 @@ class SwitchPlugin extends deploy_objects.MultiFileDeployPluginBase {
}

private getSwitchOption(target: DeployTargetSwitch): DeployTargetSwitchOption | false {
const OPTION = getCurrentOptionOf(target);
const OPTION = deploy_switch.getCurrentOptionOf(target);
if (false === OPTION) {
//TODO: show message
vscode.window.showWarningMessage(
'[vs-deploy] ' + i18.t('plugins.switch.noOptionSelected')
);

return false;
}
Expand Down
Loading

0 comments on commit b0ff680

Please sign in to comment.