Commit 3465a03a authored by akiraohgaki's avatar akiraohgaki

Merge branch 'develop'

parents 74dd500b 1a80424b
Pipeline #69 passed with stage
in 1 minute and 50 seconds
......@@ -8,7 +8,7 @@
*/
import Component from './Component.js';
import StatusManager from './StatusManager.js';
import StateManager from './StateManager.js';
import WebStorage from './WebStorage.js';
import Utility from './Utility.js';
......@@ -18,8 +18,8 @@ export default class Chirit {
return Component;
}
static get StatusManager() {
return StatusManager;
static get StateManager() {
return StateManager;
}
static get WebStorage() {
......
......@@ -11,12 +11,12 @@ export default class Component {
// Subclass should use init() instead of constructor()
constructor(element, state) {
// "element" will be Element object or selector string
// "element" should be Element object or selector string
if (typeof element === 'string') {
element = document.querySelector(element);
}
this.element = element ? element : document.createElement('div');
this.element = element || document.createElement('div');
this.innerHTML = this.element.innerHTML;
this.state = state;
......@@ -28,7 +28,7 @@ export default class Component {
_build() {
const html = this.html();
const style = this.style();
this.element.innerHTML = style ? `<style scoped>${style}</style>${html}` : html;
this.element.innerHTML = style ? `<style>${style}</style>${html}` : html;
this.script();
}
......
......@@ -7,39 +7,38 @@
* @link https://github.com/akiraohgaki/chirit
*/
export default class StatusManager {
export default class StateManager {
constructor(eventTarget) {
// "eventTarget" will be Element object or selector string
// "eventTarget" should be Element object or selector string
if (typeof eventTarget === 'string') {
eventTarget = document.querySelector(eventTarget);
}
this._eventTarget = eventTarget ? eventTarget : document;
this._eventTarget = eventTarget || document;
this._eventListener = (event) => {
event.preventDefault();
event.stopPropagation();
const params = event.detail ? event.detail : {};
this.dispatch(event.type, params);
this.dispatch(event.type, event.detail);
};
this._status = new Map();
this._states = new Map();
this._actions = new Map();
this._views = new Map();
}
getStatus() {
return this._status;
getStates() {
return this._states;
}
getState(type) {
return this._status.get(type);
return this._states.get(type);
}
registerAction(type, action, options) {
const actions = this._actions.has(type) ? this._actions.get(type) : new Map();
if (!actions.size) {
this._status.set(type, {});
this._states.set(type, {});
this._eventTarget.addEventListener(type, this._eventListener, false);
}
actions.set(action, options);
......@@ -56,7 +55,7 @@ export default class StatusManager {
}
else {
this._actions.delete(type);
this._status.delete(type);
this._states.delete(type);
this._eventTarget.removeEventListener(type, this._eventListener, false);
}
}
......@@ -99,12 +98,12 @@ export default class StatusManager {
}
Promise.all(promises)
.then((status) => {
.then((states) => {
const state = {};
for (const _state of status) {
for (const _state of states) {
Object.assign(state, _state);
}
this._status.set(type, state);
this._states.set(type, state);
if (!this._views.has(type)) {
console.log(`No views for type "${type}"`); // This case is not error
......
......@@ -13,7 +13,7 @@ export default class Utility {
const params = {};
if (window.location.search.length > 1) {
const queries = window.location.search.substring(1).split('&');
for (var i = 0; i < queries.length; i++) {
for (let i = 0; i < queries.length; i++) {
const kv = queries[i].split('=');
const key = decodeURIComponent(kv[0]);
const value = kv[1] ? decodeURIComponent(kv[1]) : '';
......@@ -67,7 +67,7 @@ export default class Utility {
}
static convertDatetimeToHumanReadable(datetime) {
// Must be datetime in ISO 8601 format
// "datetime" should be ISO 8601 formatted string
const minute = 60 * 1000;
const hour = 60 * minute;
......@@ -130,7 +130,7 @@ export default class Utility {
+ addition;
const stringArray = strings.split('');
let randomString = '';
for (var i = 0; i < length; i++) {
for (let i = 0; i < length; i++) {
randomString += stringArray[Math.floor(Math.random() * stringArray.length)];
}
return randomString;
......
......@@ -10,7 +10,7 @@
export default class WebStorage {
constructor(type = 'session', prefix = '') {
// "type" will be set 'session' or 'local'
// "type" should be "session" or "local"
this._storage = (type === 'local') ? window.localStorage : window.sessionStorage;
this._prefix = prefix;
}
......
{
"name": "chirit",
"version": "0.2.0",
"version": "0.3.0",
"description": "A front-end library.",
"author": "Akira Ohgaki",
"license": "BSD-2-Clause",
......
import Component from '../../libs/chirit/Component.js';
import Chirit from '../../libs/chirit/Chirit.js';
import packageMeta from '../../../package.json';
export default class AboutDialog extends Component {
export default class AboutDialog extends Chirit.Component {
html() {
return `
......
import Component from '../../libs/chirit/Component.js';
import Chirit from '../../libs/chirit/Chirit.js';
export default class BrowsePage extends Component {
export default class BrowsePage extends Chirit.Component {
html() {
return `
......
import Component from '../../libs/chirit/Component.js';
import Chirit from '../../libs/chirit/Chirit.js';
export default class CollectionPage extends Component {
export default class CollectionPage extends Chirit.Component {
html() {
if (!this.state) {
......
const electron = require('electron');
import Component from '../../libs/chirit/Component.js';
import Chirit from '../../libs/chirit/Chirit.js';
export default class InstalledItemsPage extends Component {
export default class InstalledItemsPage extends Chirit.Component {
html() {
if (!this.state) {
......
import Component from '../../libs/chirit/Component.js';
import Chirit from '../../libs/chirit/Chirit.js';
import StartupDialog from './StartupDialog.js';
import AboutDialog from './AboutDialog.js';
......@@ -8,7 +8,7 @@ import BrowsePage from './BrowsePage.js';
import CollectionPage from './CollectionPage.js';
import InstalledItemsPage from './InstalledItemsPage.js';
export default class Root extends Component {
export default class Root extends Chirit.Component {
html() {
return `
......
const url = require('url');
import Component from '../../libs/chirit/Component.js';
import Chirit from '../../libs/chirit/Chirit.js';
export default class OcsUrlDialog extends Component {
export default class OcsUrlDialog extends Chirit.Component {
html() {
if (!this.state) {
......
import Component from '../../libs/chirit/Component.js';
import Chirit from '../../libs/chirit/Chirit.js';
import ToolBar from './ToolBar.js';
import StatusBar from './StatusBar.js';
import MainArea from './MainArea.js';
import SidePanel from './SidePanel.js';
export default class Root extends Component {
export default class Root extends Chirit.Component {
init() {
console.log('Component building started');
......
import Component from '../../libs/chirit/Component.js';
import Chirit from '../../libs/chirit/Chirit.js';
import packageMeta from '../../../package.json';
export default class SidePanel extends Component {
export default class SidePanel extends Chirit.Component {
html() {
return `
......
import Component from '../../libs/chirit/Component.js';
import Chirit from '../../libs/chirit/Chirit.js';
import packageMeta from '../../../package.json';
export default class StartupDialog extends Component {
export default class StartupDialog extends Chirit.Component {
html() {
return `
......
import Component from '../../libs/chirit/Component.js';
import Chirit from '../../libs/chirit/Chirit.js';
import StatusBarItem from './StatusBarItem.js';
export default class StatusBar extends Component {
export default class StatusBar extends Chirit.Component {
init() {
this.items = {};
......
import Component from '../../libs/chirit/Component.js';
import Chirit from '../../libs/chirit/Chirit.js';
import Utility from '../../libs/chirit/Utility.js';
export default class StatusBarItem extends Component {
export default class StatusBarItem extends Chirit.Component {
html() {
if (!this.state) {
......@@ -125,7 +123,7 @@ export default class StatusBarItem extends Component {
&& this.element.querySelector('.statusbaritem-progress-bar')
) {
this.element.querySelector('.statusbaritem-progress-bar').value = bytesReceived / bytesTotal;
this.element.querySelector('.statusbaritem-progress-text').innerHTML = `${Utility.convertByteToHumanReadable(bytesReceived)} / ${Utility.convertByteToHumanReadable(bytesTotal)}`;
this.element.querySelector('.statusbaritem-progress-text').innerHTML = `${Chirit.Utility.convertByteToHumanReadable(bytesReceived)} / ${Chirit.Utility.convertByteToHumanReadable(bytesTotal)}`;
}
}
......
const electronStore = require('electron-store');
import Component from '../../libs/chirit/Component.js';
import Chirit from '../../libs/chirit/Chirit.js';
export default class ToolBar extends Component {
export default class ToolBar extends Chirit.Component {
init() {
if (!this.state) {
......
......@@ -7,7 +7,8 @@ const request = require('request');
const packageMeta = require('../../../package.json');
import StatusManager from '../../libs/chirit/StatusManager.js';
import Chirit from '../../libs/chirit/Chirit.js';
import Root from '../components/Root.js';
{
......@@ -16,7 +17,7 @@ import Root from '../components/Root.js';
const webSocketUrl = require(path.join(remote.app.getPath('appData'), 'ocs-manager', 'application.json')).websocket_url;
const webSocket = new WebSocket(webSocketUrl);
const statusManager = new StatusManager();
const stateManager = new Chirit.StateManager();
const root = new Root('[data-component="Root"]');
const mainWebview = root.mainArea.browsePage.element.querySelector('[data-webview="main"]');
......@@ -31,7 +32,7 @@ import Root from '../components/Root.js';
document.title = packageMeta.productName;
setupWebSocket();
setupStatusManager();
setupStateManager();
setupWebView();
setupEvent();
......@@ -39,7 +40,7 @@ import Root from '../components/Root.js';
root.mainArea.startupDialog.show();
}
statusManager.dispatch('browse-page');
stateManager.dispatch('browse-page');
}
function setupWebSocket() {
......@@ -243,16 +244,16 @@ import Root from '../components/Root.js';
};
}
function setupStatusManager() {
statusManager.registerAction('side-panel', () => {
function setupStateManager() {
stateManager.registerAction('side-panel', () => {
root.sidePanel.toggle();
});
statusManager.registerAction('about-dialog', () => {
stateManager.registerAction('about-dialog', () => {
root.mainArea.aboutDialog.show();
});
statusManager.registerAction('ocs-url-dialog', (resolve, reject, params) => {
stateManager.registerAction('ocs-url-dialog', (resolve, reject, params) => {
root.mainArea.ocsUrlDialog.update({
ocsUrl: params.ocsUrl,
providerKey: params.providerKey,
......@@ -262,21 +263,21 @@ import Root from '../components/Root.js';
root.mainArea.ocsUrlDialog.show();
});
statusManager.registerAction('process-ocs-url', (resolve, reject, params) => {
stateManager.registerAction('process-ocs-url', (resolve, reject, params) => {
root.mainArea.ocsUrlDialog.hide();
sendWebSocketMessage('', 'ItemHandler::getItemByOcsUrl', [params.ocsUrl, params.providerKey, params.contentId]);
});
statusManager.registerAction('open-destination', (resolve, reject, params) => {
stateManager.registerAction('open-destination', (resolve, reject, params) => {
const url = `file://${installTypes[params.installType].destination}`;
sendWebSocketMessage(url, 'SystemHandler::openUrl', [url]);
});
statusManager.registerAction('remove-statusbar-item', (resolve, reject, params) => {
stateManager.registerAction('remove-statusbar-item', (resolve, reject, params) => {
root.statusBar.removeItem(params);
});
statusManager.registerAction('browse-page', () => {
stateManager.registerAction('browse-page', () => {
root.toolBar.update({
active: 'start-page',
backAction: 'main-webview-back',
......@@ -290,7 +291,7 @@ import Root from '../components/Root.js';
root.mainArea.changePage('browsePage');
});
statusManager.registerAction('start-page', (resolve, reject, params) => {
stateManager.registerAction('start-page', (resolve, reject, params) => {
const store = new electronStore({name: 'application'});
if (params.startPage) {
......@@ -299,22 +300,22 @@ import Root from '../components/Root.js';
mainWebview.setAttribute('src', store.get('startPage'));
statusManager.dispatch('browse-page');
stateManager.dispatch('browse-page');
});
statusManager.registerAction('main-webview-back', () => {
stateManager.registerAction('main-webview-back', () => {
if (mainWebview.canGoBack()) {
mainWebview.goBack();
}
});
statusManager.registerAction('main-webview-forward', () => {
stateManager.registerAction('main-webview-forward', () => {
if (mainWebview.canGoForward()) {
mainWebview.goForward();
}
});
statusManager.registerAction('collection-page', () => {
stateManager.registerAction('collection-page', () => {
root.toolBar.update({
active: 'collection-page',
backAction: '',
......@@ -328,28 +329,28 @@ import Root from '../components/Root.js';
root.mainArea.changePage('collectionPage');
});
statusManager.registerAction('installed-items-page', (resolve, reject, params) => {
stateManager.registerAction('installed-items-page', (resolve, reject, params) => {
sendWebSocketMessage(params.installType, 'DesktopThemeHandler::isApplicableType', [params.installType]);
});
statusManager.registerAction('open-url', (resolve, reject, params) => {
stateManager.registerAction('open-url', (resolve, reject, params) => {
sendWebSocketMessage(params.url, 'SystemHandler::openUrl', [params.url]);
});
statusManager.registerAction('open-file', (resolve, reject, params) => {
stateManager.registerAction('open-file', (resolve, reject, params) => {
const url = `file://${params.path}`;
sendWebSocketMessage(url, 'SystemHandler::openUrl', [url]);
});
statusManager.registerAction('update-item', (resolve, reject, params) => {
stateManager.registerAction('update-item', (resolve, reject, params) => {
sendWebSocketMessage(params.path, 'UpdateHandler::update', [params.itemKey]);
});
statusManager.registerAction('apply-theme', (resolve, reject, params) => {
stateManager.registerAction('apply-theme', (resolve, reject, params) => {
sendWebSocketMessage(params.path, 'DesktopThemeHandler::applyTheme', [params.path, params.installType]);
});
statusManager.registerAction('remove-file', (resolve, reject, params) => {
stateManager.registerAction('remove-file', (resolve, reject, params) => {
sendWebSocketMessage(params.itemKey, 'ItemHandler::uninstall', [params.itemKey]);
});
}
......@@ -388,14 +389,14 @@ import Root from '../components/Root.js';
if (event.channel === 'user-profile') {
}
else if (event.channel === 'ocs-url') {
statusManager.dispatch('ocs-url-dialog', {
stateManager.dispatch('ocs-url-dialog', {
ocsUrl: event.args[0],
providerKey: event.args[1],
contentId: event.args[2]
});
}
else if (event.channel === 'external-url') {
statusManager.dispatch('open-url', {url: event.args[0]});
stateManager.dispatch('open-url', {url: event.args[0]});
}
});
}
......@@ -414,7 +415,7 @@ import Root from '../components/Root.js';
params = JSON.parse(targetElement.getAttribute('data-params'));
}
statusManager.dispatch(type, params);
stateManager.dispatch(type, params);
}
else if (event.target.closest('a[data-dispatch]')) {
event.preventDefault();
......@@ -428,13 +429,13 @@ import Root from '../components/Root.js';
params = JSON.parse(targetElement.getAttribute('data-params'));
}
statusManager.dispatch(type, params);
stateManager.dispatch(type, params);
}
else if (event.target.closest('a[target]')) {
event.preventDefault();
event.stopPropagation();
statusManager.dispatch('open-url', {url: event.target.closest('a[target]').getAttribute('href')});
stateManager.dispatch('open-url', {url: event.target.closest('a[target]').getAttribute('href')});
}
}, false);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment