|
@@ -1,5 +1,5 @@
|
|
|
import { Stage } from "../drawers/stage";
|
|
|
-class Stages {
|
|
|
+class StageManager {
|
|
|
constructor() {
|
|
|
this._width = this._getWidth();
|
|
|
this._height = this._getHeigth();
|
|
@@ -15,20 +15,17 @@ class Stages {
|
|
|
return this._stage.konvaStage;
|
|
|
}
|
|
|
getCurrentLayer() {
|
|
|
+ return this._stage.getCurrentLayer();
|
|
|
+ }
|
|
|
+ getCurrentKonvaLayer() {
|
|
|
return this._stage.getCurrentKonvaLayer();
|
|
|
}
|
|
|
create() {
|
|
|
- var id = this._files.length;
|
|
|
+ var id = this._files.length + 1;
|
|
|
this._makeTemplate(id);
|
|
|
- this._setStage(new Stage());
|
|
|
- const stage = new Konva.Stage({
|
|
|
- container: `container-${id}`,
|
|
|
- width: this._width,
|
|
|
- height: this._height
|
|
|
- });
|
|
|
- this._stage.setKonvaStage(stage);
|
|
|
- this._files.push(this._stage);
|
|
|
this._createLayer();
|
|
|
+ this._files.push(this._stage.layer);
|
|
|
+ this._cleanLayers();
|
|
|
return this._stage;
|
|
|
}
|
|
|
getFiles() {
|
|
@@ -44,13 +41,24 @@ class Stages {
|
|
|
|
|
|
_createLayer() {
|
|
|
const stage = this.getCurrentStage();
|
|
|
- if (stage != undefined) return stage.createLayer();
|
|
|
+ const layer = stage.createLayer();
|
|
|
+ return layer;
|
|
|
}
|
|
|
|
|
|
_getFiles() {
|
|
|
return _files;
|
|
|
}
|
|
|
|
|
|
+ _cleanLayers(layer) {
|
|
|
+ this._files.forEach(element => {
|
|
|
+ element.konvaLayer.hide();
|
|
|
+ });
|
|
|
+ if (layer == undefined) layer = this.getCurrentLayer();
|
|
|
+ else this._stage.setCurrentLayer(layer);
|
|
|
+ layer.konvaLayer.show();
|
|
|
+ this.getCurrentKonvaStage().draw();
|
|
|
+ }
|
|
|
+
|
|
|
_getWidth() {
|
|
|
return $("#content").width();
|
|
|
}
|
|
@@ -73,24 +81,42 @@ class Stages {
|
|
|
return _layer;
|
|
|
}
|
|
|
|
|
|
+ _selectFile(e) {
|
|
|
+ const file = $(e.currentTarget);
|
|
|
+ const id = parseInt(file.attr("file-id"));
|
|
|
+ const layer = this._files.find(function(element) {
|
|
|
+ return element.sequence == id;
|
|
|
+ });
|
|
|
+ $(".file").each(function() {
|
|
|
+ $(this).removeClass("active");
|
|
|
+ });
|
|
|
+ file.addClass("active");
|
|
|
+ if (layer != undefined) this._cleanLayers(layer);
|
|
|
+ }
|
|
|
+
|
|
|
_bootstrap() {
|
|
|
$("#files").empty();
|
|
|
$("body").on("click", "#new-document", this._evenNewDocument.bind(this));
|
|
|
+ $("body").on("click", ".file", this._selectFile.bind(this));
|
|
|
+ $("#stages").append(`<div id="container" class="stage"></div>`);
|
|
|
+ const stage = new Konva.Stage({
|
|
|
+ container: `container`,
|
|
|
+ width: this._width,
|
|
|
+ height: this._height
|
|
|
+ });
|
|
|
+ this._setStage(new Stage());
|
|
|
+ this._stage.setKonvaStage(stage);
|
|
|
this.create();
|
|
|
}
|
|
|
|
|
|
_makeTemplate(id) {
|
|
|
- $(".stage").each(function() {
|
|
|
- $(this).addClass("hidden");
|
|
|
- });
|
|
|
$(".file").each(function() {
|
|
|
$(this).removeClass("active");
|
|
|
});
|
|
|
- $("#stages").append(`<div id="container-${id}" class="stage"></div>`);
|
|
|
$("#files").append(
|
|
|
- `<li class="file active"><button>New Document ${id + 1}</button></li>`
|
|
|
+ `<li class="file active" file-id="${id}"><button>New Document ${id}</button></li>`
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export const stages = new Stages();
|
|
|
+export const stageManager = new StageManager();
|