Skip to content

Commit

Permalink
annotation articles, article close button, tests, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
framefactory committed Apr 17, 2019
1 parent 8dd1f88 commit fca72a3
Show file tree
Hide file tree
Showing 22 changed files with 183 additions and 65 deletions.
2 changes: 1 addition & 1 deletion libs/ff-browser
2 changes: 1 addition & 1 deletion libs/ff-scene
2 changes: 1 addition & 1 deletion libs/ff-ui
Submodule ff-ui updated from 3278d9 to da99ae
2 changes: 1 addition & 1 deletion source/client/annotations/AnnotationSprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class AnnotationElement extends CustomElement
this.classList.add("sv-annotation");
}

protected onClick(event: PointerEvent)
protected onClick(event: MouseEvent)
{
event.stopPropagation();
this.sprite.emitClickEvent();
Expand Down
32 changes: 23 additions & 9 deletions source/client/annotations/BeamSprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import * as THREE from "three";

import math from "@ff/core/math";

import { customElement, PropertyValues } from "@ff/ui/CustomElement";
import { customElement, PropertyValues, html, render } from "@ff/ui/CustomElement";
import Button from "@ff/ui/Button";

import AnnotationSprite, { Annotation, AnnotationElement } from "./AnnotationSprite";

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -99,7 +101,7 @@ export default class BeamSprite extends AnnotationSprite
class BeamAnnotation extends AnnotationElement
{
protected titleElement: HTMLDivElement;
protected leadElement: HTMLDivElement;
protected contentElement: HTMLDivElement;
protected wrapperElement: HTMLDivElement;
protected handler = 0;
protected isExpanded = true;
Expand All @@ -110,13 +112,15 @@ class BeamAnnotation extends AnnotationElement
{
super(sprite);

this.onClickArticle = this.onClickArticle.bind(this);

this.titleElement = this.appendElement("div");
this.titleElement.classList.add("sv-content", "sv-title");

this.wrapperElement = this.appendElement("div");

this.leadElement = this.createElement("div", null, this.wrapperElement);
this.leadElement.classList.add("sv-content", "sv-description");
this.contentElement = this.createElement("div", null, this.wrapperElement);
this.contentElement.classList.add("sv-content", "sv-description");
}

getOpacity()
Expand Down Expand Up @@ -144,7 +148,11 @@ class BeamAnnotation extends AnnotationElement
const annotation = this.sprite.annotation.data;

this.titleElement.innerText = annotation.title;
this.leadElement.innerText = annotation.lead;

const contentTemplate = html`<p>${annotation.lead}</p>
${annotation.articleId ? html`<ff-button inline text="Read more..." icon="document" @click=${this.onClickArticle}></ff-button>` : null}`;

render(contentTemplate, this.contentElement);

this.targetOpacity = annotation.visible ? 1 : 0;

Expand All @@ -155,16 +163,22 @@ class BeamAnnotation extends AnnotationElement

if (this.isExpanded) {
this.classList.add("sv-expanded");
this.leadElement.style.display = "inherit";
this.leadElement.style.height = this.leadElement.scrollHeight + "px";
this.contentElement.style.display = "inherit";
this.contentElement.style.height = this.contentElement.scrollHeight + "px";

}
else {
this.classList.remove("sv-expanded");
this.leadElement.style.height = "0";
this.handler = window.setTimeout(() => this.leadElement.style.display = "none", 300);
this.contentElement.style.height = "0";
this.handler = window.setTimeout(() => this.contentElement.style.display = "none", 300);

}
}
}

protected onClickArticle(event: MouseEvent)
{
event.stopPropagation();
this.sprite.emitLinkEvent(this.sprite.annotation.data.articleId);
}
}
68 changes: 48 additions & 20 deletions source/client/components/CVAnnotationView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import AnnotationSprite, { IAnnotationClickEvent, IAnnotationLinkEvent } from ".

import PinSprite from "../annotations/PinSprite";
import BeamSprite from "../annotations/BeamSprite";
import CVMeta from "./CVMeta";
import CVReader from "./CVReader";

////////////////////////////////////////////////////////////////////////////////

Expand All @@ -50,6 +52,8 @@ const _inputs = {
style: types.Enum("Annotation.Style", EAnnotationStyle, EAnnotationStyle.Default),
scale: types.Scale("Annotation.Scale", 1),
offset: types.Number("Annotation.Offset"),
article: types.Option("Annotation.Article", []),
image: types.String("Annotation.Image"),
tilt: types.Number("Annotation.Tilt"),
azimuth: types.Number("Annotation.Azimuth"),
};
Expand All @@ -69,6 +73,16 @@ export default class CVAnnotationView extends CObject3D
protected get model() {
return this.getComponent(CVModel2);
}
protected get meta() {
return this.getComponent(CVMeta, true);
}
protected get reader() {
return this.getGraphComponent(CVReader);
}
protected get articles() {
const meta = this.meta;
return meta ? meta.articles : null;
}

get activeAnnotation() {
return this._activeAnnotation;
Expand Down Expand Up @@ -96,6 +110,21 @@ export default class CVAnnotationView extends CObject3D
ins.scale.setValue(annotation ? annotation.data.scale : 1, true);
ins.offset.setValue(annotation ? annotation.data.offset : 0, true);

const articles = this.articles;
if (articles) {
const names = articles.items.map(article => article.data.title);
names.unshift("(none)");
ins.article.setOptions(names);
const article = annotation ? articles.getById(annotation.data.articleId) : null;
ins.article.setValue(article ? articles.getIndexOf(article) + 1 : 0, true);
}
else {
ins.article.setOptions([ "(none)" ]);
ins.article.setValue(0);
}

ins.image.setValue(annotation ? annotation.data.imageUri : "", true);

this.emit<IAnnotationsUpdateEvent>({ type: "update", annotation });
}
}
Expand All @@ -109,6 +138,7 @@ export default class CVAnnotationView extends CObject3D
this.onSpriteLink = this.onSpriteLink.bind(this);

this.on<IPointerEvent>("pointer-up", this.onPointerUp, this);
this.system.on<IPointerEvent>("pointer-up", this.onPointerUp, this);

this.object3D = new HTMLSpriteGroup();
}
Expand All @@ -126,34 +156,31 @@ export default class CVAnnotationView extends CObject3D
object3D.updateMatrix();
}

if (ins.title.changed) {
if (annotation) {
if (annotation) {
if (ins.title.changed) {
annotation.set("title", ins.title.value);
}
}
if (ins.lead.changed) {
if (annotation) {
if (ins.lead.changed) {
annotation.set("lead", ins.lead.value);
}
}
if (ins.style.changed) {
if (annotation) {
if (ins.style.changed) {
annotation.set("style", ins.style.getValidatedValue());
this.createSprite(annotation);
}
}
if (ins.scale.changed) {
if (annotation) {
if (ins.scale.changed) {
annotation.set("scale", ins.scale.value);
}
}
if (ins.offset.changed) {
if (annotation) {
if (ins.offset.changed) {
annotation.set("offset", ins.offset.value);
}
}
if (ins.image.changed) {
annotation.set("imageUri", ins.image.value);
}
if (ins.article.changed) {
const article = this.articles.getAt(ins.article.getValidatedValue() - 1);
annotation.set("articleId", article ? article.id : "");
}

if (annotation) {
this.updateSprite(annotation);
this.emit<IAnnotationsUpdateEvent>({ type: "update", annotation });
}
Expand All @@ -176,7 +203,9 @@ export default class CVAnnotationView extends CObject3D
dispose()
{
(this.object3D as HTMLSpriteGroup).dispose();

this.off<IPointerEvent>("pointer-up", this.onPointerUp, this);
this.system.off<IPointerEvent>("pointer-up", this.onPointerUp, this);

this._viewports.forEach(viewport => viewport.off("dispose", this.onViewportDispose, this));
this._viewports.clear();
Expand Down Expand Up @@ -269,9 +298,7 @@ export default class CVAnnotationView extends CObject3D
target = target.parent as AnnotationSprite;
}

if (target) {
this.activeAnnotation = target.annotation;
}
this.activeAnnotation = target && target.annotation;
}

protected onViewportDispose(event: IViewportDisposeEvent)
Expand All @@ -287,7 +314,8 @@ export default class CVAnnotationView extends CObject3D

protected onSpriteLink(event: IAnnotationLinkEvent)
{

this.reader.ins.articleId.setValue(event.annotation.data.articleId);
this.reader.ins.enabled.setValue(true);
}

protected createSprite(annotation: Annotation)
Expand Down
4 changes: 2 additions & 2 deletions source/client/components/CVAnnotationsTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ export default class CVAnnotationsTask extends CVTask

protected onActiveNode(previous: NVNode, next: NVNode)
{
const prevAnnotations = previous ? previous.getComponent(CVAnnotationView) : null;
const nextAnnotations = next ? next.getComponent(CVAnnotationView) : null;
const prevAnnotations = previous ? previous.getComponent(CVAnnotationView, true) : null;
const nextAnnotations = next ? next.getComponent(CVAnnotationView, true) : null;

if (prevAnnotations) {
prevAnnotations.off<IAnnotationsUpdateEvent>("update", this.emitUpdateEvent, this);
Expand Down
6 changes: 5 additions & 1 deletion source/client/components/CVArticlesTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import ArticlesTaskView from "../ui/story/ArticlesTaskView";
import CAssetManager from "@ff/scene/components/CAssetManager";
import CVAssetWriter from "./CVAssetWriter";
import MessageBox from "@ff/ui/MessageBox";
import uniqueId from "@ff/core/uniqueId";

////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -93,7 +94,10 @@ export default class CVArticlesTask extends CVTask
const activeAsset = activeArticle ? this.assetManager.getAssetByPath(activeArticle.data.uri) : null;

if (meta && ins.create.changed) {
meta.articles.append(new Article());
const article = new Article();
article.data.uri = `articles/new-article-${article.id}.html`;
meta.articles.append(article);
this.reader.ins.articleId.setValue(article.id);
}

if (activeArticle) {
Expand Down
6 changes: 2 additions & 4 deletions source/client/components/CVReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default class CVReader extends Component
protected _articles: Dictionary<IArticleEntry>;

get snapshotKeys() {
return [ "enabled" ];
return [ "enabled", "articleId" ];
}

get articles() {
Expand Down Expand Up @@ -95,13 +95,11 @@ export default class CVReader extends Component
const article = entry && entry.article;
outs.node.setValue(entry && entry.node);
outs.article.setValue(article);
outs.content.setValue("");

if (article) {
this.readArticle(article);
}
else {
outs.content.setValue("");
}
}

return true;
Expand Down
9 changes: 9 additions & 0 deletions source/client/components/CVToursTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

import { Node } from "@ff/graph/Component";
import CTweenMachine, { EEasingCurve } from "@ff/graph/components/CTweenMachine";

import CVTask, { types } from "./CVTask";
Expand Down Expand Up @@ -63,6 +64,14 @@ export default class CVToursTask extends CVTask
tours: CVTours = null;
machine: CTweenMachine = null;

constructor(node: Node, id: string)
{
super(node, id);

const configuration = this.configuration;
configuration.bracketsVisible = false;
}

update(context)
{
const ins = this.ins;
Expand Down
2 changes: 1 addition & 1 deletion source/client/components/CVViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class CVViewer extends CRenderable
ins = this.addInputs(CVViewer.ins);

get snapshotKeys() {
return [ "shader", "exposure" ];
return [ "shader", "exposure", "annotationsVisible" ];
}

create()
Expand Down
14 changes: 8 additions & 6 deletions source/client/models/Annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ export default class Annotation extends Document<IAnnotation, IAnnotationJSON>
if (data.tags.length > 0) {
json.tags = data.tags;
}
if (data.articles.length > 0) {
//TODO: Articles/IDs
//json.articles = data.articles.slice();
if (data.articleId) {
json.articleId = data.articleId;
}
if (data.imageUri) {
json.imageUri = data.imageUri;
}
if (data.style !== EAnnotationStyle.Default) {
json.style = EAnnotationStyle[data.style];
Expand Down Expand Up @@ -124,9 +126,9 @@ export default class Annotation extends Document<IAnnotation, IAnnotationJSON>
data.title = json.title || "";
data.lead = json.lead || "";
data.tags = json.tags || [];
//TODO: Articles/IDs
data.articles = [];
//data.articles = json.articles ? json.articles.slice() : [];

data.articleId = json.articleId || "";
data.imageUri = json.imageUri || "";

data.style = EAnnotationStyle[json.style] || EAnnotationStyle.Default;
data.visible = json.visible !== undefined ? json.visible : true;
Expand Down
Loading

0 comments on commit fca72a3

Please sign in to comment.