|
@@ -27,20 +27,16 @@ import { TypeOptionController } from '../../stores/effects/database/field/type_o
|
|
|
import { makeSingleSelectTypeOptionContext } from '../../stores/effects/database/field/type_option/type_option_context';
|
|
|
import { SelectOptionBackendService } from '../../stores/effects/database/cell/select_option_bd_svc';
|
|
|
import { Log } from '$app/utils/log';
|
|
|
-import { ViewBackendService } from '$app/stores/effects/folder/view/view_bd_svc';
|
|
|
-import { WorkspaceBackendService } from '$app/stores/effects/folder/workspace/workspace_bd_svc';
|
|
|
+import { WorkspaceController } from '../../stores/effects/workspace/workspace_controller';
|
|
|
|
|
|
-// Create a database view for specific layout type
|
|
|
+// Create a database page for specific layout type
|
|
|
// Do not use it production code. Just for testing
|
|
|
export async function createTestDatabaseView(layout: ViewLayoutPB): Promise<ViewPB> {
|
|
|
const workspaceSetting: WorkspaceSettingPB = await FolderEventGetCurrentWorkspace().then((result) => result.unwrap());
|
|
|
- const wsSvc = new WorkspaceBackendService(workspaceSetting.workspace.id);
|
|
|
- const viewRes = await wsSvc.createView({ name: 'New Grid', layoutType: layout });
|
|
|
- if (viewRes.ok) {
|
|
|
- return viewRes.val;
|
|
|
- } else {
|
|
|
- throw Error(viewRes.val.msg);
|
|
|
- }
|
|
|
+ const wsSvc = new WorkspaceController(workspaceSetting.workspace.id);
|
|
|
+ const viewRes = await wsSvc.createView({ name: 'New Grid', layout });
|
|
|
+
|
|
|
+ return viewRes;
|
|
|
}
|
|
|
|
|
|
export async function openTestDatabase(viewId: string): Promise<DatabaseController> {
|
|
@@ -56,9 +52,11 @@ export async function assertTextCell(
|
|
|
const cellController = await makeTextCellController(fieldId, rowInfo, databaseController).then((result) =>
|
|
|
result.unwrap()
|
|
|
);
|
|
|
+
|
|
|
cellController.subscribeChanged({
|
|
|
onCellChanged: (value) => {
|
|
|
const cellContent = value.unwrap();
|
|
|
+
|
|
|
if (cellContent !== expectedContent) {
|
|
|
throw Error('Text cell content is not match');
|
|
|
}
|
|
@@ -76,6 +74,7 @@ export async function editTextCell(
|
|
|
const cellController = await makeTextCellController(fieldId, rowInfo, databaseController).then((result) =>
|
|
|
result.unwrap()
|
|
|
);
|
|
|
+
|
|
|
await cellController.saveCellData(content);
|
|
|
}
|
|
|
|
|
@@ -87,6 +86,7 @@ export async function makeTextCellController(
|
|
|
const builder = await makeCellControllerBuilder(fieldId, rowInfo, FieldType.RichText, databaseController).then(
|
|
|
(result) => result.unwrap()
|
|
|
);
|
|
|
+
|
|
|
return Some(builder.build() as TextCellController);
|
|
|
}
|
|
|
|
|
@@ -98,6 +98,7 @@ export async function makeNumberCellController(
|
|
|
const builder = await makeCellControllerBuilder(fieldId, rowInfo, FieldType.Number, databaseController).then(
|
|
|
(result) => result.unwrap()
|
|
|
);
|
|
|
+
|
|
|
return Some(builder.build() as NumberCellController);
|
|
|
}
|
|
|
|
|
@@ -109,6 +110,7 @@ export async function makeSingleSelectCellController(
|
|
|
const builder = await makeCellControllerBuilder(fieldId, rowInfo, FieldType.SingleSelect, databaseController).then(
|
|
|
(result) => result.unwrap()
|
|
|
);
|
|
|
+
|
|
|
return Some(builder.build() as SelectOptionCellController);
|
|
|
}
|
|
|
|
|
@@ -120,6 +122,7 @@ export async function makeMultiSelectCellController(
|
|
|
const builder = await makeCellControllerBuilder(fieldId, rowInfo, FieldType.MultiSelect, databaseController).then(
|
|
|
(result) => result.unwrap()
|
|
|
);
|
|
|
+
|
|
|
return Some(builder.build() as SelectOptionCellController);
|
|
|
}
|
|
|
|
|
@@ -131,6 +134,7 @@ export async function makeDateCellController(
|
|
|
const builder = await makeCellControllerBuilder(fieldId, rowInfo, FieldType.DateTime, databaseController).then(
|
|
|
(result) => result.unwrap()
|
|
|
);
|
|
|
+
|
|
|
return Some(builder.build() as DateCellController);
|
|
|
}
|
|
|
|
|
@@ -142,6 +146,7 @@ export async function makeCheckboxCellController(
|
|
|
const builder = await makeCellControllerBuilder(fieldId, rowInfo, FieldType.Checkbox, databaseController).then(
|
|
|
(result) => result.unwrap()
|
|
|
);
|
|
|
+
|
|
|
return Some(builder.build() as CheckboxCellController);
|
|
|
}
|
|
|
|
|
@@ -153,6 +158,7 @@ export async function makeURLCellController(
|
|
|
const builder = await makeCellControllerBuilder(fieldId, rowInfo, FieldType.DateTime, databaseController).then(
|
|
|
(result) => result.unwrap()
|
|
|
);
|
|
|
+
|
|
|
return Some(builder.build() as URLCellController);
|
|
|
}
|
|
|
|
|
@@ -167,8 +173,10 @@ export async function makeCellControllerBuilder(
|
|
|
const fieldController = databaseController.fieldController;
|
|
|
const rowController = new RowController(rowInfo, fieldController, rowCache);
|
|
|
const cellByFieldId = await rowController.loadCells();
|
|
|
+
|
|
|
for (const cellIdentifier of cellByFieldId.values()) {
|
|
|
const builder = new CellControllerBuilder(cellIdentifier, cellCache, fieldController);
|
|
|
+
|
|
|
if (cellIdentifier.fieldId === fieldId) {
|
|
|
return Some(builder);
|
|
|
}
|
|
@@ -179,6 +187,7 @@ export async function makeCellControllerBuilder(
|
|
|
|
|
|
export function findFirstFieldInfoWithFieldType(rowInfo: RowInfo, fieldType: FieldType) {
|
|
|
const fieldInfo = rowInfo.fieldInfos.find((element) => element.field.field_type === fieldType);
|
|
|
+
|
|
|
if (fieldInfo === undefined) {
|
|
|
return None;
|
|
|
} else {
|
|
@@ -189,6 +198,7 @@ export function findFirstFieldInfoWithFieldType(rowInfo: RowInfo, fieldType: Fie
|
|
|
export async function assertFieldName(viewId: string, fieldId: string, fieldType: FieldType, expected: string) {
|
|
|
const svc = new TypeOptionBackendService(viewId);
|
|
|
const typeOptionPB = await svc.getTypeOption(fieldId, fieldType).then((result) => result.unwrap());
|
|
|
+
|
|
|
if (typeOptionPB.field.name !== expected) {
|
|
|
throw Error('Expect field name:' + expected + 'but receive:' + typeOptionPB.field.name);
|
|
|
}
|
|
@@ -197,6 +207,7 @@ export async function assertFieldName(viewId: string, fieldId: string, fieldType
|
|
|
export async function assertNumberOfFields(viewId: string, expected: number) {
|
|
|
const svc = new DatabaseBackendService(viewId);
|
|
|
const databasePB = await svc.openDatabase().then((result) => result.unwrap());
|
|
|
+
|
|
|
if (databasePB.fields.length !== expected) {
|
|
|
throw Error('Expect number of fields:' + expected + 'but receive:' + databasePB.fields.length);
|
|
|
}
|
|
@@ -205,6 +216,7 @@ export async function assertNumberOfFields(viewId: string, expected: number) {
|
|
|
export async function assertNumberOfRows(viewId: string, expected: number) {
|
|
|
const svc = new DatabaseBackendService(viewId);
|
|
|
const databasePB = await svc.openDatabase().then((result) => result.unwrap());
|
|
|
+
|
|
|
if (databasePB.rows.length !== expected) {
|
|
|
throw Error('Expect number of rows:' + expected + 'but receive:' + databasePB.rows.length);
|
|
|
}
|
|
@@ -212,9 +224,11 @@ export async function assertNumberOfRows(viewId: string, expected: number) {
|
|
|
|
|
|
export async function assertNumberOfRowsInGroup(viewId: string, groupId: string, expected: number) {
|
|
|
const svc = new DatabaseBackendService(viewId);
|
|
|
+
|
|
|
await svc.openDatabase();
|
|
|
|
|
|
const group = await svc.getGroup(groupId).then((result) => result.unwrap());
|
|
|
+
|
|
|
if (group.rows.length !== expected) {
|
|
|
throw Error('Expect number of rows in group:' + expected + 'but receive:' + group.rows.length);
|
|
|
}
|
|
@@ -229,10 +243,13 @@ export async function createSingleSelectOptions(viewId: string, fieldInfo: Field
|
|
|
.then((result) => result.unwrap());
|
|
|
|
|
|
const backendSvc = new SelectOptionBackendService(viewId, fieldInfo.field.id);
|
|
|
+
|
|
|
for (const optionName of optionNames) {
|
|
|
const option = await backendSvc.createOption({ name: optionName }).then((result) => result.unwrap());
|
|
|
+
|
|
|
singleSelectTypeOptionPB.options.splice(0, 0, option);
|
|
|
}
|
|
|
+
|
|
|
await singleSelectTypeOptionContext.setTypeOption(singleSelectTypeOptionPB);
|
|
|
return singleSelectTypeOptionContext;
|
|
|
}
|