@vived/host 3.12.0 → 3.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,8 @@ const Entities_3 = require("../Entities");
9
9
  const PMs_1 = require("../PMs");
10
10
  const UCs_2 = require("../UCs");
11
11
  const setupStandardHostHandlers_1 = require("../../Handler/setupStandardHostHandlers");
12
+ const Handler_1 = require("../../Handler");
13
+ const submitActivityAssetHandlerSandbox_1 = require("../UCs/submitActivityAssetHandlerSandbox");
12
14
  function setupAppSandbox(appID, appObjects) {
13
15
  const ao = appObjects.getOrCreate(appID);
14
16
  // Entities
@@ -27,6 +29,10 @@ function setupAppSandbox(appID, appObjects) {
27
29
  PMs_1.makeSandboxStatePM(ao);
28
30
  PMs_1.makeShowInspectorPM(ao);
29
31
  PMs_1.makeStartInZSpacePM(ao);
32
+ const submitActivityAssetUC = appObjects.getSingleton(Handler_1.SubmitActivityAssetHandler.type);
33
+ if (submitActivityAssetUC) {
34
+ submitActivityAssetUC.action = submitActivityAssetHandlerSandbox_1.makeSubmitActivityAssetHandlerSandbox(appObjects);
35
+ }
30
36
  return entity;
31
37
  }
32
38
  exports.setupAppSandbox = setupAppSandbox;
@@ -0,0 +1,3 @@
1
+ import { HostAppObjectRepo } from "../../../HostAppObject";
2
+ import { SubmitActivityAssetAction } from "../../Handler/UCs/SubmitActivityAssetHandler";
3
+ export declare function makeSubmitActivityAssetHandlerSandbox(appObjects: HostAppObjectRepo): SubmitActivityAssetAction;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeSubmitActivityAssetHandlerSandbox = void 0;
4
+ const __1 = require("..");
5
+ const Assets_1 = require("../../Assets");
6
+ function makeSubmitActivityAssetHandlerSandbox(appObjects) {
7
+ return function submitActivityAssetHandler(assetFile, callback) {
8
+ const sandbox = __1.AppSandboxEntity.get(appObjects);
9
+ if (!sandbox) {
10
+ appObjects.submitError("makeSubmitActivityAssetHandlerSandbox", "Unable to find AppSandboxEntity");
11
+ callback(undefined);
12
+ return;
13
+ }
14
+ if (!sandbox.mockActivityID) {
15
+ appObjects.submitError("makeSubmitActivityAssetHandlerSandbox", "No activity ID found");
16
+ callback(undefined);
17
+ return;
18
+ }
19
+ const ownerID = sandbox.mockActivityID;
20
+ const newAssetData = {
21
+ name: "Activity Asset",
22
+ description: "Asset for activity " + ownerID,
23
+ file: assetFile,
24
+ owner: ownerID
25
+ };
26
+ const newAssetUC = Assets_1.NewAssetUC.get(appObjects);
27
+ if (!newAssetUC) {
28
+ appObjects.submitError("makeSubmitActivityAssetHandlerSandbox", "Unable to find NewAssetUC");
29
+ callback(undefined);
30
+ return;
31
+ }
32
+ newAssetUC.create(newAssetData).then((assetID) => {
33
+ callback(assetID);
34
+ });
35
+ };
36
+ }
37
+ exports.makeSubmitActivityAssetHandlerSandbox = makeSubmitActivityAssetHandlerSandbox;
@@ -17,6 +17,7 @@ function setupAssetsForSandbox(appObjects) {
17
17
  UCs_1.makeGetAssetFileUC(assetRepoAO);
18
18
  UCs_1.makeGetAssetUC(assetRepoAO);
19
19
  UCs_1.makePrefetchAssets(assetRepoAO);
20
+ UCs_1.makeNewAssetUC(assetRepoAO);
20
21
  UCs_1.makeNewAppAssetUC(appAssetsAO);
21
22
  UCs_1.makeGetAppAssetUC(appAssetsAO);
22
23
  // PMs
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeNewAssetUC = exports.NewAssetUC = void 0;
4
4
  const HostAppObject_1 = require("../../../HostAppObject");
5
- const Dialog_1 = require("../../Dialog");
6
5
  const UCs_1 = require("../../VivedAPI/UCs");
7
6
  const Entities_1 = require("../Entities");
8
7
  class NewAssetUC extends HostAppObject_1.HostAppObjectUC {
@@ -23,44 +22,23 @@ class NewAssetUCImp extends NewAssetUC {
23
22
  const postNewAsset = this.postNewAsset;
24
23
  const assetRepo = this.assetRepo;
25
24
  if (!postNewAsset || !assetRepo) {
26
- return Promise.reject();
25
+ return Promise.reject(new Error("Missing dependencies"));
27
26
  }
28
- return new Promise((resolve) => {
29
- var _a;
30
- const { description, file, name, owner } = data;
31
- const newAssetData = {
32
- description,
33
- name,
34
- file,
35
- ownerID: owner
36
- };
37
- const spinnerDialog = (_a = this.spinnerFactory) === null || _a === void 0 ? void 0 : _a.make({
38
- title: "New Asset",
39
- message: "Posting new asset..."
40
- });
41
- postNewAsset(newAssetData)
42
- .then((resp) => {
43
- const newAsset = assetRepo.assetFactory(resp.id);
44
- newAsset.setFile(file);
45
- newAsset.description = description;
46
- newAsset.name = name;
47
- newAsset.filename = resp.filename;
48
- assetRepo.add(newAsset);
49
- spinnerDialog === null || spinnerDialog === void 0 ? void 0 : spinnerDialog.close();
50
- resolve(resp.id);
51
- })
52
- .catch((e) => {
53
- var _a;
54
- this.error("create new asset error: " + e.message);
55
- spinnerDialog === null || spinnerDialog === void 0 ? void 0 : spinnerDialog.close();
56
- const dialogDTO = {
57
- buttonLabel: "OK",
58
- message: `Something went wrong when creating a new app asset. Check the console. ${e.message}`,
59
- title: "New Asset Error"
60
- };
61
- (_a = this.alertFactory) === null || _a === void 0 ? void 0 : _a.make(dialogDTO);
62
- resolve("");
63
- });
27
+ const { description, file, name, owner } = data;
28
+ const newAssetData = {
29
+ description,
30
+ name,
31
+ file,
32
+ ownerID: owner
33
+ };
34
+ return postNewAsset(newAssetData).then((resp) => {
35
+ const newAsset = assetRepo.assetFactory(resp.id);
36
+ newAsset.setFile(file);
37
+ newAsset.description = description;
38
+ newAsset.name = name;
39
+ newAsset.filename = resp.filename;
40
+ assetRepo.add(newAsset);
41
+ return resp.id;
64
42
  });
65
43
  };
66
44
  this.appObjects.registerSingleton(this);
@@ -72,10 +50,4 @@ class NewAssetUCImp extends NewAssetUC {
72
50
  get assetRepo() {
73
51
  return this.getCachedSingleton(Entities_1.AssetRepo.type);
74
52
  }
75
- get spinnerFactory() {
76
- return this.getCachedSingleton(Dialog_1.MakeSpinnerDialogUC.type);
77
- }
78
- get alertFactory() {
79
- return this.getCachedSingleton(Dialog_1.MakeAlertDialogUC.type);
80
- }
81
53
  }
@@ -16,6 +16,7 @@ export declare class AlertDialogEntity extends Dialog {
16
16
  readonly message: string;
17
17
  readonly buttonLabel: string;
18
18
  readonly preventOutsideDismiss: boolean;
19
+ hasBeenClosed: boolean;
19
20
  private postClose?;
20
21
  close: () => void;
21
22
  private _isOpen;
@@ -9,7 +9,9 @@ class AlertDialogEntity extends DialogQueue_1.Dialog {
9
9
  super(appObject, AlertDialogEntity.type);
10
10
  this.dialogType = exports.alertDialogType;
11
11
  this.preventOutsideDismiss = false;
12
+ this.hasBeenClosed = false;
12
13
  this.close = () => {
14
+ this.hasBeenClosed = true;
13
15
  this.isOpen = false;
14
16
  if (this.postClose) {
15
17
  this.postClose();
@@ -18,6 +18,7 @@ export declare class ConfirmDialogEntity extends Dialog {
18
18
  readonly confirmButtonLabel: string;
19
19
  readonly cancelButtonLabel: string;
20
20
  readonly preventOutsideDismiss = true;
21
+ hasBeenClosed: boolean;
21
22
  private postCancel?;
22
23
  cancel: () => void;
23
24
  private postConfirm?;
@@ -9,13 +9,16 @@ class ConfirmDialogEntity extends DialogQueue_1.Dialog {
9
9
  super(appObject, ConfirmDialogEntity.type);
10
10
  this.dialogType = exports.confirmDialogType;
11
11
  this.preventOutsideDismiss = true;
12
+ this.hasBeenClosed = false;
12
13
  this.cancel = () => {
14
+ this.hasBeenClosed = true;
13
15
  this.isOpen = false;
14
16
  if (this.postCancel) {
15
17
  this.postCancel();
16
18
  }
17
19
  };
18
20
  this.confirm = () => {
21
+ this.hasBeenClosed = true;
19
22
  this.isOpen = false;
20
23
  if (this.postConfirm) {
21
24
  this.postConfirm();
@@ -3,6 +3,7 @@ export declare abstract class Dialog extends HostAppObjectEntity {
3
3
  abstract dialogType: string;
4
4
  abstract preventOutsideDismiss: boolean;
5
5
  abstract isOpen: boolean;
6
+ abstract hasBeenClosed: boolean;
6
7
  }
7
8
  export declare abstract class DialogQueue extends HostAppObjectEntity {
8
9
  static type: string;
@@ -29,17 +29,30 @@ class DialogRepoImp extends DialogQueue {
29
29
  this.notifyOnChange();
30
30
  };
31
31
  this.activeDialogHasClosed = () => {
32
- const activeDialog = this.activeDialog;
33
- if (activeDialog !== null) {
32
+ const currentActiveDialog = this.activeDialog;
33
+ if (currentActiveDialog !== null) {
34
+ currentActiveDialog.removeChangeObserver(this.notifyOnChange);
35
+ this.filterOutClosedDialogs();
34
36
  this.dialogQueue.splice(0, 1);
35
37
  const newActiveDialog = this.activeDialog;
36
38
  if (newActiveDialog !== null) {
37
39
  newActiveDialog.isOpen = true;
38
40
  }
39
- activeDialog.removeChangeObserver(this.notifyOnChange);
40
41
  this.notifyOnChange();
41
42
  }
42
43
  };
44
+ this.filterOutClosedDialogs = () => {
45
+ const dialogsToKeep = [];
46
+ this.dialogQueue.forEach((dialog) => {
47
+ if (!dialog.hasBeenClosed) {
48
+ dialogsToKeep.push(dialog);
49
+ }
50
+ else {
51
+ dialog.removeChangeObserver(this.notifyOnChange);
52
+ }
53
+ });
54
+ this.dialogQueue = dialogsToKeep;
55
+ };
43
56
  this.appObjects.registerSingleton(this);
44
57
  }
45
58
  get activeDialog() {
@@ -1,5 +1,5 @@
1
- import { HostAppObject, HostAppObjectRepo } from '../../../HostAppObject';
2
- import { Dialog } from './DialogQueue';
1
+ import { HostAppObject, HostAppObjectRepo } from "../../../HostAppObject";
2
+ import { Dialog } from "./DialogQueue";
3
3
  export interface DialogMarkDownEditorDTO {
4
4
  initialText: string;
5
5
  onConfirm: (text: string) => void;
@@ -11,6 +11,7 @@ export declare class MarkDownEditorDialogEntity extends Dialog {
11
11
  readonly dialogType = "MARKDOWN_EDITOR";
12
12
  readonly initialText: string;
13
13
  readonly preventOutsideDismiss = true;
14
+ hasBeenClosed: boolean;
14
15
  cancel: () => void;
15
16
  private postConfirm;
16
17
  confirm: (text: string) => void;
@@ -3,16 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MarkDownEditorDialogEntity = exports.markDownEditorDialogType = void 0;
4
4
  const Entities_1 = require("../../../Entities");
5
5
  const DialogQueue_1 = require("./DialogQueue");
6
- exports.markDownEditorDialogType = 'MARKDOWN_EDITOR';
6
+ exports.markDownEditorDialogType = "MARKDOWN_EDITOR";
7
7
  class MarkDownEditorDialogEntity extends DialogQueue_1.Dialog {
8
8
  constructor(data, appObject) {
9
9
  super(appObject, MarkDownEditorDialogEntity.type);
10
10
  this.dialogType = exports.markDownEditorDialogType;
11
11
  this.preventOutsideDismiss = true;
12
+ this.hasBeenClosed = false;
12
13
  this.cancel = () => {
14
+ this.hasBeenClosed = true; // added setting hasBeenClosed
13
15
  this.isOpen = false;
14
16
  };
15
17
  this.confirm = (text) => {
18
+ this.hasBeenClosed = true; // added setting hasBeenClosed
16
19
  this.isOpen = false;
17
20
  this.postConfirm(text);
18
21
  };
@@ -23,12 +26,12 @@ class MarkDownEditorDialogEntity extends DialogQueue_1.Dialog {
23
26
  static get(assetID, appObjects) {
24
27
  const appObject = appObjects.get(assetID);
25
28
  if (!appObject) {
26
- appObjects.submitWarning('MarkDownEditorDialogEntity.get', 'Unable to find app object');
29
+ appObjects.submitWarning("MarkDownEditorDialogEntity.get", "Unable to find app object");
27
30
  return undefined;
28
31
  }
29
32
  const uc = appObject.getComponent(MarkDownEditorDialogEntity.type);
30
33
  if (!uc) {
31
- appObjects.submitWarning('MarkDownEditorDialogEntity.get', 'App Object does not have DialogAlertEntity');
34
+ appObjects.submitWarning("MarkDownEditorDialogEntity.get", "App Object does not have DialogAlertEntity");
32
35
  return undefined;
33
36
  }
34
37
  return uc;
@@ -41,4 +44,4 @@ class MarkDownEditorDialogEntity extends DialogQueue_1.Dialog {
41
44
  }
42
45
  }
43
46
  exports.MarkDownEditorDialogEntity = MarkDownEditorDialogEntity;
44
- MarkDownEditorDialogEntity.type = 'MarkDownEditorDialogEntity';
47
+ MarkDownEditorDialogEntity.type = "MarkDownEditorDialogEntity";
@@ -6,6 +6,7 @@ export declare class SelectModelDialogEntity extends Dialog {
6
6
  static type: string;
7
7
  static get(assetID: string, appObjects: HostAppObjectRepo): SelectModelDialogEntity | undefined;
8
8
  readonly dialogType = "SELECT_CHANNEL_MODEL";
9
+ hasBeenClosed: boolean;
9
10
  private _isOpen;
10
11
  get isOpen(): boolean;
11
12
  set isOpen(val: boolean);
@@ -8,6 +8,7 @@ class SelectModelDialogEntity extends DialogQueue_1.Dialog {
8
8
  constructor(appObject) {
9
9
  super(appObject, SelectModelDialogEntity.type);
10
10
  this.dialogType = exports.selectModelDialogType;
11
+ this.hasBeenClosed = false;
11
12
  this._isOpen = new Entities_1.MemoizedBoolean(false, this.notifyOnChange);
12
13
  this.preventOutsideDismiss = true;
13
14
  this.memoizedIsReady = new Entities_1.MemoizedBoolean(false, this.notifyOnChange);
@@ -19,6 +19,7 @@ export declare class SpinnerDialogEntity extends Dialog {
19
19
  private _isOpen;
20
20
  set isOpen(open: boolean);
21
21
  get isOpen(): boolean;
22
+ hasBeenClosed: boolean;
22
23
  close: () => void;
23
24
  constructor(data: DialogSpinnerDTO, appObject: HostAppObject);
24
25
  }
@@ -11,7 +11,9 @@ class SpinnerDialogEntity extends DialogQueue_1.Dialog {
11
11
  this.mininumuLifespan = 2000;
12
12
  this.preventOutsideDismiss = true;
13
13
  this._isOpen = new Entities_1.MemoizedBoolean(false, this.notifyOnChange);
14
+ this.hasBeenClosed = false;
14
15
  this.close = () => {
16
+ this.hasBeenClosed = true;
15
17
  if (this.createdAt === undefined) {
16
18
  this.isOpen = false;
17
19
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vived/host",
3
- "version": "3.12.0",
3
+ "version": "3.12.1",
4
4
  "description": "Public Host package for the VIVED Learning App system",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",