mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-30 09:35:39 -05:00
Another code layering (#4037)
* working on formatting * fixed basic lint errors; starting moving things to their appropriate location * formatting * update tslint to match the version of vscode we have * remove unused code * work in progress fixing layering * formatting * moved connection management service to platform * formatting * add missing file * moving more servies * formatting * moving more services * formatting * wip * moving more services * formatting * move css file * add missing svgs * moved the rest of services * formatting * changing around some references * formatting * revert tslint * revert some changes that brake things * formatting * fix tests * fix testzx * fix tests * fix tests * fix compile issue
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IInsightDialogActionContext } from 'sql/workbench/services/insights/common/insightsDialogService';
|
||||
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
import * as nls from 'vs/nls';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
|
||||
export class CopyInsightDialogSelectionAction extends Action {
|
||||
public static ID = 'workbench.action.insights.copySelection';
|
||||
public static LABEL = nls.localize('workbench.action.insights.copySelection', "Copy Cell");
|
||||
|
||||
constructor(
|
||||
id: string, label: string,
|
||||
@IClipboardService private _clipboardService: IClipboardService
|
||||
) {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
public run(event?: IInsightDialogActionContext): TPromise<any> {
|
||||
this._clipboardService.writeText(event.cellData);
|
||||
return TPromise.as(void 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IInsightsDialogModel, ListResource } from 'sql/workbench/services/insights/common/insightsDialogService';
|
||||
import { IInsightsConfigDetails, IInsightsLabel } from 'sql/parts/dashboard/widgets/insights/interfaces';
|
||||
import { Conditional } from 'sql/parts/dashboard/common/interfaces';
|
||||
|
||||
import { Event, Emitter, debounceEvent } from 'vs/base/common/event';
|
||||
|
||||
export class InsightsDialogModel implements IInsightsDialogModel {
|
||||
private _rows: string[][];
|
||||
private _columns: string[];
|
||||
private _insight: IInsightsConfigDetails;
|
||||
|
||||
private _onDataChangeEmitter: Emitter<void> = new Emitter<void>();
|
||||
private _onDataChangeEvent: Event<void> = this._onDataChangeEmitter.event;
|
||||
public onDataChange: Event<void> = debounceEvent(this._onDataChangeEvent, (last, event) => event, 75, false);
|
||||
|
||||
public set insight(insight: IInsightsConfigDetails) {
|
||||
this._insight = insight;
|
||||
}
|
||||
|
||||
public set rows(val: string[][]) {
|
||||
this._rows = val;
|
||||
this._onDataChangeEmitter.fire();
|
||||
}
|
||||
|
||||
public get rows(): string[][] {
|
||||
return this._rows;
|
||||
}
|
||||
|
||||
public set columns(val: string[]) {
|
||||
this._columns = val;
|
||||
this._onDataChangeEmitter.fire();
|
||||
}
|
||||
|
||||
public get columns(): string[] {
|
||||
return this._columns;
|
||||
}
|
||||
|
||||
public reset(): void {
|
||||
this._columns = [];
|
||||
this._rows = [];
|
||||
this._onDataChangeEmitter.fire();
|
||||
}
|
||||
|
||||
public getListResources(labelIndex: number, valueIndex: number): ListResource[] {
|
||||
return this.rows.map((item) => {
|
||||
let label = item[labelIndex];
|
||||
let value = item[valueIndex];
|
||||
let state = this.calcInsightState(value);
|
||||
let data = item;
|
||||
let icon = typeof this._insight.label === 'object' ? this._insight.label.icon : undefined;
|
||||
let rval = { title: false, label, value, icon, data };
|
||||
if (state) {
|
||||
rval[state.type] = state.val;
|
||||
}
|
||||
return rval;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the state of the item value passed based on the insight conditions
|
||||
* @param item item to determine state for
|
||||
* @returns json that specifies whether the state is an icon or color and the val of that state
|
||||
*/
|
||||
private calcInsightState(item: string): { type: 'stateColor' | 'stateIcon', val: string } {
|
||||
if (typeof this._insight.label === 'string') {
|
||||
return undefined;
|
||||
} else {
|
||||
let label = <IInsightsLabel>this._insight.label;
|
||||
for (let cond of label.state) {
|
||||
switch (Conditional[cond.condition.if]) {
|
||||
case Conditional.always:
|
||||
return cond.color
|
||||
? { type: 'stateColor', val: cond.color }
|
||||
: { type: 'stateIcon', val: cond.icon };
|
||||
case Conditional.equals:
|
||||
if (item === cond.condition.equals) {
|
||||
return cond.color
|
||||
? { type: 'stateColor', val: cond.color }
|
||||
: { type: 'stateIcon', val: cond.icon };
|
||||
}
|
||||
break;
|
||||
case Conditional.notEquals:
|
||||
if (item !== cond.condition.equals) {
|
||||
return cond.color
|
||||
? { type: 'stateColor', val: cond.color }
|
||||
: { type: 'stateIcon', val: cond.icon };
|
||||
}
|
||||
break;
|
||||
case Conditional.greaterThanOrEquals:
|
||||
if (parseInt(item) >= parseInt(cond.condition.equals)) {
|
||||
return cond.color
|
||||
? { type: 'stateColor', val: cond.color }
|
||||
: { type: 'stateIcon', val: cond.icon };
|
||||
}
|
||||
break;
|
||||
case Conditional.greaterThan:
|
||||
if (parseInt(item) > parseInt(cond.condition.equals)) {
|
||||
return cond.color
|
||||
? { type: 'stateColor', val: cond.color }
|
||||
: { type: 'stateIcon', val: cond.icon };
|
||||
}
|
||||
break;
|
||||
case Conditional.lessThanOrEquals:
|
||||
if (parseInt(item) <= parseInt(cond.condition.equals)) {
|
||||
return cond.color
|
||||
? { type: 'stateColor', val: cond.color }
|
||||
: { type: 'stateIcon', val: cond.icon };
|
||||
}
|
||||
break;
|
||||
case Conditional.lessThan:
|
||||
if (parseInt(item) < parseInt(cond.condition.equals)) {
|
||||
return cond.color
|
||||
? { type: 'stateColor', val: cond.color }
|
||||
: { type: 'stateIcon', val: cond.icon };
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// if we got to this point, there was no matching conditionals therefore no valid state
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
import { IInsightsConfigDetails, IInsightsConfig } from 'sql/parts/dashboard/widgets/insights/interfaces';
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { BaseActionContext } from 'sql/workbench/common/actions';
|
||||
|
||||
export interface IInsightsDialogModel {
|
||||
rows: string[][];
|
||||
columns: string[];
|
||||
getListResources(labelIndex: number, valueIndex: number): ListResource[];
|
||||
reset(): void;
|
||||
onDataChange: Event<void>;
|
||||
insight: IInsightsConfigDetails;
|
||||
}
|
||||
|
||||
export interface ListResource {
|
||||
value: string;
|
||||
label: string;
|
||||
icon?: string;
|
||||
data?: string[];
|
||||
stateColor?: string;
|
||||
stateIcon?: string;
|
||||
}
|
||||
|
||||
export const IInsightsDialogService = createDecorator<IInsightsDialogService>('insightsDialogService');
|
||||
|
||||
export interface IInsightsDialogService {
|
||||
_serviceBrand: any;
|
||||
show(input: IInsightsConfig, connectionProfile: IConnectionProfile): void;
|
||||
close();
|
||||
}
|
||||
|
||||
export interface IInsightDialogActionContext extends BaseActionContext {
|
||||
cellData: string;
|
||||
}
|
||||
|
||||
/* Regex that matches the form `${value}` */
|
||||
export const insertValueRegex: RegExp = /\${(.*?)\}/;
|
||||
Reference in New Issue
Block a user