Skip to content

Commit

Permalink
Cleanup views system
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Mar 8, 2022
1 parent c0f494c commit 3e494f6
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 40 deletions.
23 changes: 7 additions & 16 deletions dev/Knoin/AbstractViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import ko from 'ko';

import { addObservablesTo, addComputablesTo, addSubscribablesTo } from 'External/ko';
import { keyScope, SettingsGet, leftPanelDisabled } from 'Common/Globals';
import { ViewType, showScreenPopup } from 'Knoin/Knoin';
import { ViewTypePopup, showScreenPopup } from 'Knoin/Knoin';

import { SaveSettingsStep } from 'Common/Enums';

class AbstractView {
constructor(templateID, type)
{
// Object.defineProperty(this, 'viewModelTemplateID', { value: templateID });
// this.viewModelTemplateID = this.constructor.name;
this.viewModelTemplateID = templateID;
this.viewModelTemplateID = templateID || this.constructor.name.replace('UserView', '');
this.viewType = type;
this.viewModelDom = null;

Expand Down Expand Up @@ -57,7 +56,7 @@ export class AbstractViewPopup extends AbstractView
{
constructor(name)
{
super('Popups' + name, ViewType.Popup);
super('Popups' + name, ViewTypePopup);
this.keyScope.scope = name;
this.modalVisible = ko.observable(false).extend({ rateLimit: 0 });
shortcuts.add('escape,close', '', name, () => {
Expand Down Expand Up @@ -92,19 +91,11 @@ AbstractViewPopup.hidden = function() {
return !this.__vm || !this.__vm.modalVisible();
}

export class AbstractViewCenter extends AbstractView
{
constructor(templateID)
{
super(templateID, ViewType.Content);
}
}

export class AbstractViewLeft extends AbstractView
{
constructor(templateID)
{
super(templateID, ViewType.Left);
super(templateID, 'Left');
this.leftPanelDisabled = leftPanelDisabled;
}
}
Expand All @@ -113,7 +104,7 @@ export class AbstractViewRight extends AbstractView
{
constructor(templateID)
{
super(templateID, ViewType.Right);
super(templateID, 'Right');
}
}

Expand Down Expand Up @@ -158,9 +149,9 @@ export class AbstractViewSettings
}
}

export class AbstractViewLogin extends AbstractViewCenter {
export class AbstractViewLogin extends AbstractView {
constructor(templateID) {
super(templateID);
super(templateID, 'Content');
this.hideSubmitButton = SettingsGet('hideSubmitButton');
this.formError = ko.observable(false).extend({ falseTimeout: 500 });
}
Expand Down
13 changes: 4 additions & 9 deletions dev/Knoin/Knoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const
vm = new ViewModelClass(vmScreen),
id = vm.viewModelTemplateID,
position = vm.viewType || '',
dialog = ViewType.Popup === position,
dialog = ViewTypePopup === position,
vmPlace = position ? doc.getElementById('rl-' + position.toLowerCase()) : null;

ViewModelClass.__builded = true;
Expand All @@ -49,7 +49,7 @@ const
vm.viewModelDom = vmDom;
ViewModelClass.__dom = vmDom;

if (ViewType.Popup === position) {
if (ViewTypePopup === position) {
vm.close = () => hideScreenPopup(ViewModelClass);

// Firefox / Safari HTMLDialogElement not defined
Expand Down Expand Up @@ -133,7 +133,7 @@ const
if (
ViewModelClass.__vm &&
ViewModelClass.__dom &&
ViewType.Popup !== ViewModelClass.__vm.viewType
ViewTypePopup !== ViewModelClass.__vm.viewType
) {
fn(ViewModelClass.__vm, ViewModelClass.__dom);
}
Expand Down Expand Up @@ -230,12 +230,7 @@ const


export const
ViewType = {
Popup: 'Popups',
Left: 'Left',
Right: 'Right',
Content: 'Content'
},
ViewTypePopup = 'Popups',

/**
* @param {Function} ViewModelClassToShow
Expand Down
4 changes: 2 additions & 2 deletions dev/Screen/Admin/Login.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AbstractScreen } from 'Knoin/AbstractScreen';

import { LoginAdminView } from 'View/Admin/Login';
import { AdminLoginView } from 'View/Admin/Login';

export class LoginAdminScreen extends AbstractScreen {
constructor() {
super('login', [LoginAdminView]);
super('login', [AdminLoginView]);
}

onShow() {
Expand Down
6 changes: 3 additions & 3 deletions dev/Screen/User/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import { UserSettingsFolders } from 'Settings/User/Folders';
import { UserSettingsThemes } from 'Settings/User/Themes';

import { SystemDropDownUserView } from 'View/User/SystemDropDown';
import { MenuSettingsUserView } from 'View/User/Settings/Menu';
import { PaneSettingsUserView } from 'View/User/Settings/Pane';
import { SettingsMenuUserView } from 'View/User/Settings/Menu';
import { SettingsPaneUserView } from 'View/User/Settings/Pane';

export class SettingsUserScreen extends AbstractSettingsScreen {
constructor() {
super([SystemDropDownUserView, MenuSettingsUserView, PaneSettingsUserView]);
super([SystemDropDownUserView, SettingsMenuUserView, SettingsPaneUserView]);

const views = [
UserSettingsGeneral
Expand Down
2 changes: 1 addition & 1 deletion dev/View/Admin/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Remote from 'Remote/Admin/Fetch';
import { decorateKoCommands } from 'Knoin/Knoin';
import { AbstractViewLogin } from 'Knoin/AbstractViews';

export class LoginAdminView extends AbstractViewLogin {
export class AdminLoginView extends AbstractViewLogin {
constructor() {
super('AdminLogin');

Expand Down
2 changes: 1 addition & 1 deletion dev/View/User/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const SignMeOff = 0,

export class LoginUserView extends AbstractViewLogin {
constructor() {
super('Login');
super();

this.addObservables({
loadingDesc: SettingsGet('LoadingDescription'),
Expand Down
2 changes: 1 addition & 1 deletion dev/View/User/MailBox/FolderList.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { setExpandedFolder } from 'Model/FolderCollection';

export class MailFolderList extends AbstractViewLeft {
constructor() {
super('MailFolderList');
super();

this.oContentScrollable = null;

Expand Down
2 changes: 1 addition & 1 deletion dev/View/User/MailBox/MessageList.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const

export class MailMessageList extends AbstractViewRight {
constructor() {
super('MailMessageList');
super();

this.bPrefetch = false;
this.emptySubjectValue = '';
Expand Down
2 changes: 1 addition & 1 deletion dev/View/User/MailBox/MessageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const

export class MailMessageView extends AbstractViewRight {
constructor() {
super('MailMessageView');
super();

const
/**
Expand Down
4 changes: 2 additions & 2 deletions dev/View/User/Settings/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { getFolderInboxName } from 'Common/Cache';

import { AbstractViewLeft } from 'Knoin/AbstractViews';

export class MenuSettingsUserView extends AbstractViewLeft {
export class SettingsMenuUserView extends AbstractViewLeft {
/**
* @param {Object} screen
*/
constructor(screen) {
super('SettingsMenu');
super();

this.menu = screen.menu;
}
Expand Down
4 changes: 2 additions & 2 deletions dev/View/User/Settings/Pane.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { ThemeStore } from 'Stores/Theme';

import { AbstractViewRight } from 'Knoin/AbstractViews';

export class PaneSettingsUserView extends AbstractViewRight {
export class SettingsPaneUserView extends AbstractViewRight {
constructor() {
super('SettingsPane');
super();

this.isMobile = ThemeStore.isMobile;
this.leftPanelDisabled = leftPanelDisabled;
Expand Down
2 changes: 1 addition & 1 deletion dev/View/User/SystemDropDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { getNotification } from 'Common/Translator';

export class SystemDropDownUserView extends AbstractViewRight {
constructor() {
super('SystemDropDown');
super();

this.allowAccounts = SettingsCapa('AdditionalAccounts');

Expand Down

0 comments on commit 3e494f6

Please sign in to comment.