Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Gallery System #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plattar-api/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export { SceneVideo } from "./types/scene/scene-video";
export { SceneVolumetric } from "./types/scene/scene-volumetric";
export { SceneYoutube } from "./types/scene/scene-youtube";
export { SceneScript } from "./types/scene/scene-script";
export { SceneGallery } from "./types/scene/scene-gallery";
export { SceneGalleryImage } from "./types/scene/scene-gallery-image";

// export Page and its types
export { Page } from "./types/page/page";
Expand Down
4 changes: 4 additions & 0 deletions plattar-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const SceneVideo = require("./types/scene/scene-video.js");
const SceneVolumetric = require("./types/scene/scene-volumetric.js");
const SceneYoutube = require("./types/scene/scene-youtube.js");
const SceneScript = require("./types/scene/scene-script.js");
const SceneGallery = require("./types/scene/scene-gallery.js");
const SceneGalleryImage = require("./types/scene/scene-gallery-image.js");

// import Page and its types
const Page = require("./types/page/page.js");
Expand Down Expand Up @@ -103,6 +105,8 @@ module.exports = {
SceneVolumetric,
SceneYoutube,
SceneScript,
SceneGallery,
SceneGalleryImage,
// page and types
Page,
CardButton,
Expand Down
8 changes: 8 additions & 0 deletions plattar-api/types/scene/scene-gallery-image.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { SceneBase } from "./scene-base";

export class SceneGalleryImage extends SceneBase {
static type(): "scenegalleryimage";

get attributes(): any;
set overrideAttributes(attributes: any);
}
9 changes: 9 additions & 0 deletions plattar-api/types/scene/scene-gallery-image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const PlattarBase = require("../interfaces/plattar-base.js");

class SceneGalleryImage extends PlattarBase {
static type() {
return "scenegalleryimage";
}
}

module.exports = SceneGalleryImage;
8 changes: 8 additions & 0 deletions plattar-api/types/scene/scene-gallery.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { SceneBase } from "./scene-base";

export class SceneGallery extends SceneBase {
static type(): "scenegallery";

get attributes(): any;
set overrideAttributes(attributes: any);
}
9 changes: 9 additions & 0 deletions plattar-api/types/scene/scene-gallery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const PlattarBase = require("../interfaces/plattar-base.js");

class SceneGallery extends PlattarBase {
static type() {
return "scenegallery";
}
}

module.exports = SceneGallery;
29 changes: 23 additions & 6 deletions plattar-api/util/plattar-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const SceneVideo = require("../types/scene/scene-video.js");
const SceneVolumetric = require("../types/scene/scene-volumetric.js");
const SceneYoutube = require("../types/scene/scene-youtube.js");
const SceneScript = require("../types/scene/scene-script.js");
const SceneGallery = require("../types/scene/scene-gallery.js");
const SceneGalleryImage = require("../types/scene/scene-gallery-image.js");

// import Page types and its children
const Page = require("../types/page/page.js");
Expand Down Expand Up @@ -115,16 +117,22 @@ PlattarUtil.reconstruct = (parent, json, options) => {
if (Array.isArray(data)) {
data.forEach((item) => {
const construct = PlattarUtil.create(key, item.id, server);
construct._attributes = item.attributes || {};

parent.relationships._put(construct);
if (construct) {
construct._attributes = item.attributes || {};

parent.relationships._put(construct);
}
});
}
else {
const construct = PlattarUtil.create(key, data.id, server);
construct._attributes = data.attributes || {};

parent.relationships._put(construct);
if (construct) {
construct._attributes = data.attributes || {};

parent.relationships._put(construct);
}
}
}
}
Expand Down Expand Up @@ -156,7 +164,11 @@ PlattarUtil.create = (type, id, server) => {
// dynamic class matching from a string type
const _DynamicClass = PlattarUtil.match(type);

return new _DynamicClass(id, server);
if (_DynamicClass) {
return new _DynamicClass(id, server);
}

return undefined;
};

/**
Expand All @@ -183,6 +195,8 @@ PlattarUtil.match = (type) => {
case SceneVolumetric.type(): return SceneVolumetric;
case SceneYoutube.type(): return SceneYoutube;
case SceneScript.type(): return SceneScript;
case SceneGallery.type(): return SceneGallery;
case SceneGalleryImage.type(): return SceneGalleryImage;
case Page.type(): return Page;
case CardButton.type(): return CardButton;
case CardHTML.type(): return CardHTML;
Expand Down Expand Up @@ -218,7 +232,10 @@ PlattarUtil.match = (type) => {
case Rating.type(): return Rating;
case Solution.type(): return Solution;
case Folder.type(): return Folder;
default: throw new Error("PlattarUtil.match(type) - provided type of \"" + type + "\" does not exist and cannot be created");
default: {
console.warn("PlattarUtil.match(type) - provided type of \"" + type + "\" does not exist and cannot be created");
return undefined;
}
}
};

Expand Down
Loading