Files
azuredatastudio/src/sql/workbench/contrib/grid/common/dataService.ts
Alex Ma 32a89676f1 EditDataTest Merge (removal of angular in edit data) (#8951)
* another commmit

* Now shows blank grid, nullcheck in queryhistory

* renamed onAngularLoaded to onComponentLoaded

* removed whitespace

* removed unused dataservice import

* now displays data, need to fix contextmenu actions

* minor changes

* another small commit

* added timeout for context menu

* updated queryhistoryserviceimpl

* removed log

* added commented out contextmenuregistrations

* context menu now shows up need to test

* added plugin registration WIP

* another commit

* yet another commit

* added wip function

* Clean up commit

* more cleaning up

* removed accessor

* renamed instances of parts

* updated

* fixed merge conflicts

* refactored bootstrapparams

* fixed code

* small changes to format

* set editable to true for testing

* added more options

* moved options to separate variable

* added texteditorclass for later

* added rudimentary create editor support

* changed grid.resize.emit to fire

* added formatterfactory

* added tslint disable

* removed debug message

* added more functions from Slickgrid.ts

* added wip handlechanges function

* another change

* added columndefinitions

* Managed to display table using handlechange

* added ability to edit for now

* added changes to table creation

* added setupevents

* added onInit

* fixed sql.xlf

* minor changes

* tidying up

* more cleaning up

* changed console.log messages to debug ones.

* added this.enableEditing

* made changes to getoverridabletexteditor

* fixed opencontextmenu

* added timeout for detectChange

* need to find way to run oncontext asynchronously

* check stuff

* oncontextmenu now no longer constantly refreshes

* added oldDataRows for future use

* add check for datarows

* small changes made

* set enableediting to true

* more changes

* added additional information for handlechanges

* another change

* more changes

* set enableediting to true

* fixed rerender

* added small test mssage for jquery

* text editor is in getOverridableTextEditorClass()

* removed debug messages

* added transparency for input.editor for table.

* need to find out how to add editing for input

* Added grid div to make slickgrid style work

* reinstated selected.

* disabled selectedcellcssclass

* restored selected

* removed selectionmodel due to not being found in the original code

* Added externalSelectionModel for correct results

* removed selectionmodel as its not used.

* WIP work on refreshresultsets

* temporarily bringing back selection model for now

* added getSelectedRanges from slickgrid into Table

* added getselectedranges from slickgrid into table

* small cleanup changes

* removed detectchanges

* removed last of detectchanges

* return of toprownumber

* no need for toprownumber

* removed isColumnLoading

* some small formatting

* fixed null check

* added back todo comment

* Added fix for context menu

* small change

* added missing value to getFormatter in grid panel

* added fix for last row italics

* added fix for null inconsistencies

* Some consolidation

* added new check for null cells

* minor change

* add check for selections (usually undefined)

* removed null check in formatters

* Some changes made

* changed plugins array

* removed todo

* renamed some variables

* deleted html file

* Moved height and width to editData.css

* added box-sizing for slickgridcontainer

* fixed editdatagridpanel css

* added small changes

* More minor changes

* removed params

* renamed refreshResultsets to refreshDatasets

* removed the  stylesheet.remove lines

* added fix for null

* removed tables

* removed spaces in refreshGrid

* More minor changes

* optimization and formatting

* removal of unnecessary lines

* replaced firstRender in some parts with firstLoad

* Added timeout fix

* minor changes

* Still testing

* cleanup

* restored 200 timeout

* added styling changes for editdata

* removed angular2-slickgrid and added styling

* Small formatting changes to editDataGridPanel

* consolidation
2020-01-28 14:24:39 -08:00

156 lines
5.2 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Subject } from 'rxjs/Subject';
import { EditUpdateCellResult, EditSubsetResult, EditCreateRowResult } from 'azdata';
import { IQueryModelService } from 'sql/platform/query/common/queryModel';
import { ResultSerializer } from 'sql/workbench/contrib/query/common/resultSerializer';
import { ISaveRequest } from 'sql/workbench/contrib/grid/common/interfaces';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
/**
* DataService handles the interactions between QueryModel and app.component. Thus, it handles
* query running and grid interaction communication for a single URI.
*/
export class DataService {
public queryEventObserver: Subject<any>;
public gridContentObserver: Subject<any>;
private editQueue: Promise<any>;
constructor(
private _uri: string,
@IInstantiationService private _instantiationService: IInstantiationService,
@IQueryModelService private _queryModel: IQueryModelService
) {
this.queryEventObserver = new Subject();
this.gridContentObserver = new Subject();
this.editQueue = Promise.resolve();
}
/**
* Get a specified number of rows starting at a specified row. Should only
* be used for edit sessions.
* @param rowStart The row to start retrieving from (inclusive)
* @param numberOfRows The maximum number of rows to return
*/
getEditRows(rowStart: number, numberOfRows: number): Promise<EditSubsetResult | undefined> {
return this._queryModel.getEditRows(this._uri, rowStart, numberOfRows);
}
updateCell(rowId: number, columnId: number, newValue: string): Thenable<EditUpdateCellResult> {
const self = this;
self.editQueue = self.editQueue.then(() => {
return self._queryModel.updateCell(self._uri, rowId, columnId, newValue).then(result => {
return result;
}, error => {
// Start our editQueue over due to the rejected promise
self.editQueue = Promise.resolve();
return Promise.reject(error);
});
});
return self.editQueue;
}
commitEdit(): Thenable<void> {
const self = this;
self.editQueue = self.editQueue.then(() => {
return self._queryModel.commitEdit(self._uri).then(result => {
return result;
}, error => {
// Start our editQueue over due to the rejected promise
self.editQueue = Promise.resolve();
return Promise.reject(error);
});
});
return self.editQueue;
}
createRow(): Thenable<EditCreateRowResult> {
const self = this;
self.editQueue = self.editQueue.then(() => {
return self._queryModel.createRow(self._uri).then(result => {
return result;
}, error => {
// Start our editQueue over due to the rejected promise
self.editQueue = Promise.resolve();
return Promise.reject(error);
});
});
return self.editQueue;
}
deleteRow(rowId: number): Thenable<void> {
const self = this;
self.editQueue = self.editQueue.then(() => {
return self._queryModel.deleteRow(self._uri, rowId).then(result => {
return result;
}, error => {
// Start our editQueue over due to the rejected promise
self.editQueue = Promise.resolve();
self._queryModel.showCommitError(error.message);
return Promise.reject(error);
});
});
return self.editQueue;
}
revertCell(rowId: number, columnId: number): Thenable<void> {
const self = this;
self.editQueue = self.editQueue.then(() => {
return self._queryModel.revertCell(self._uri, rowId, columnId).then(result => {
return result;
}, error => {
// Start our editQueue over due to the rejected promise
self.editQueue = Promise.resolve();
return Promise.reject(error);
});
});
return self.editQueue;
}
revertRow(rowId: number): Thenable<void> {
const self = this;
self.editQueue = self.editQueue.then(() => {
return self._queryModel.revertRow(self._uri, rowId).then(result => {
return result;
}, error => {
// Start our editQueue over due to the rejected promise
self.editQueue = Promise.resolve();
return Promise.reject(error);
});
});
return self.editQueue;
}
/**
* send request to save the selected result set as csv
* @param uri of the calling document
* @param batchId The batch id of the batch with the result to save
* @param resultId The id of the result to save as csv
*/
sendSaveRequest(saveRequest: ISaveRequest): void {
let serializer = this._instantiationService.createInstance(ResultSerializer);
serializer.saveResults(this._uri, saveRequest);
}
/**
* Sends a copy request
* @param selection The selection range to copy
* @param batchId The batch id of the result to copy from
* @param resultId The result id of the result to copy from
* @param includeHeaders [Optional]: Should column headers be included in the copy selection
*/
copyResults(selection: Slick.Range[], batchId: number, resultId: number, includeHeaders?: boolean): void {
this._queryModel.copyResults(this._uri, selection, batchId, resultId, includeHeaders);
}
onLoaded(): void {
this._queryModel.onLoaded(this._uri);
}
}