Skip to content

Commit

Permalink
Merge pull request #25 from datasci4health/development
Browse files Browse the repository at this point in the history
Styling the DCC State Selector
  • Loading branch information
santanche authored May 21, 2019
2 parents c5a63a1 + 3db5999 commit 1fd7740
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
36 changes: 25 additions & 11 deletions src/adonisjs/public/dccs/components/dcc-state-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ class DCCStateSelector extends DCCBase {
this._presentationState = this.querySelector("#presentation-state");
*/

let template = document.createElement("template");
template.innerHTML = DCCStateSelector.templateElements;

this._shadow = this.attachShadow({mode: "open"});
this._shadow.appendChild(template.content.cloneNode(true));

this._presentation = this._shadow.querySelector("#presentation-dcc");
this._presentationState = this._shadow.querySelector("#presentation-state");


this._showState = this._showState.bind(this);
this._hideState = this._hideState.bind(this);
this._changeState = this._changeState.bind(this);
Expand All @@ -43,6 +33,28 @@ class DCCStateSelector extends DCCBase {
}

async connectedCallback() {
const theme = await MessageBus.ext.request("control/_current_theme_name/get");

DCCStateSelector.templateElements =
"<style> @import '" +
Basic.service.themeStyleResolver(theme.message, "dcc-state-selector.css") +
"' </style>" +
`<span id="presentation-dcc">
<span id="presentation-text"><slot></slot></span>
<span id="presentation-state"></span>
</span>`;

let template = document.createElement("template");
template.innerHTML = DCCStateSelector.templateElements;

// Basic.service.replaceStyle(template, null, newValue, "dcc-state-selector.css");

this._shadow = this.attachShadow({mode: "open"});
this._shadow.appendChild(template.content.cloneNode(true));

this._presentation = this._shadow.querySelector("#presentation-dcc");
this._presentationState = this._shadow.querySelector("#presentation-state");

// <TODO> limited: considers only one group per page
this.completeId = this.id;
if (!this.hasAttribute("states") && MessageBus.page.hasSubscriber("dcc/request/selector-states")) {
Expand Down Expand Up @@ -247,8 +259,9 @@ class DCCGroupSelector extends DCCBase {
}
}

(function() {
(async function() {

/*
DCCStateSelector.templateElements =
`<style>
@import "css/dcc-state-selector.css"
Expand All @@ -257,6 +270,7 @@ DCCStateSelector.templateElements =
<span id="presentation-text"><slot></slot></span>
<span id="presentation-state"></span>
</span>`;
*/

DCCStateSelector.elementTag = "dcc-state-selector";
customElements.define(DCCStateSelector.elementTag, DCCStateSelector);
Expand Down
10 changes: 6 additions & 4 deletions src/adonisjs/public/infra/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,20 @@ class Basic {
return result;
}

themeStyleResolver(theme) {
return "../themes/" + theme + "/css/theme.css";
themeStyleResolver(theme, cssFile) {
return "../themes/" + theme + "/css/" + cssFile;
}

replaceStyle(targetDocument, oldCSS, newTheme) {
replaceStyle(targetDocument, oldCSS, newTheme, cssFile) {
if (oldCSS)
targetDocument.head.removeChild(oldCSS);

const cssF = (cssFile) ? cssFile : "theme.css";

let newCSS = document.createElement("link");
newCSS.setAttribute("rel", "stylesheet");
newCSS.setAttribute("type", "text/css");
newCSS.setAttribute("href", this.themeStyleResolver(newTheme));
newCSS.setAttribute("href", this.themeStyleResolver(newTheme, cssF));
targetDocument.head.appendChild(newCSS);

return newCSS;
Expand Down
4 changes: 2 additions & 2 deletions src/adonisjs/public/infra/bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class MessageBus {
}

async publish(topic, message) {
console.log(topic);
console.log(message);
// console.log(topic);
// console.log(message);
for (let l in this._listeners)
if (this.matchTopic(l, topic))
this._listeners[l].callback(topic, message);
Expand Down
12 changes: 12 additions & 0 deletions src/adonisjs/public/player/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class PlayerManager {
this._nextKnot = 1;
}

/* <TODO>
A commom code for shared functionalities between player and author
******/

get currentThemeFamily() {
return this._currentThemeFamily;
}
Expand All @@ -55,6 +59,11 @@ class PlayerManager {
Basic.service.replaceStyle(document, this._currentThemeCSS, newValue);
}

requestCurrentThemeFamily(topic, message) {
MessageBus.ext.publish(MessageBus.buildResponseTopic(topic, message),
this.currentThemeFamily);
}

/*
* Event handlers
* **************
Expand All @@ -64,6 +73,9 @@ class PlayerManager {
switch (topic) {
case "control/register": this.register(); break;
case "control/signin": this.signIn(); break;
case "control/_current_theme_name/get" :
this.requestCurrentThemeFamily(topic, message);
break;
}
}

Expand Down

0 comments on commit 1fd7740

Please sign in to comment.