From 6b87441ded1bf2ef6e18d3d4fec3c4680df1c9e5 Mon Sep 17 00:00:00 2001 From: Eugen Ciur <eugen@papermerge.com> Date: Mon, 21 Feb 2022 20:20:29 +0100 Subject: [PATCH] consider inbox tab --- app/base/routing.js | 16 ++++++++------ app/components/breadcrumb/index.hbs | 10 ++++++++- app/components/dual_link_to/index.hbs | 6 +++++- app/components/nav/sidebar.hbs | 15 +++++++------ app/components/nav/sidebar.js | 31 --------------------------- app/controllers/authenticated.js | 1 - app/models/user.js | 9 ++++++++ app/router.js | 1 - app/routes/application.js | 11 ---------- app/routes/authenticated/nodes.js | 6 +++++- app/templates/authenticated.hbs | 4 ++-- app/templates/authenticated/inbox.hbs | 1 - 12 files changed, 48 insertions(+), 63 deletions(-) delete mode 100644 app/components/nav/sidebar.js delete mode 100644 app/templates/authenticated/inbox.hbs diff --git a/app/base/routing.js b/app/base/routing.js index 6763fe1..3b68a6b 100644 --- a/app/base/routing.js +++ b/app/base/routing.js @@ -8,8 +8,8 @@ export default class BaseRoute extends Route { @service currentUser; async beforeModel(transition) { - this.session.requireAuthentication(transition, 'login'); + await this.currentUser.loadCurrentUser(); if (this.currentUser.user) { @@ -17,14 +17,16 @@ export default class BaseRoute extends Route { } } - setupController() { + async setupController() { super.setupController(...arguments); + let app_controller = this.controllerFor('authenticated'), + home_folder, + inbox_folder; - let app_controller = this.controllerFor('authenticated'); - - this.currentUser.user.getHomeFolder().then((home_folder) => { - app_controller.set('home_folder', home_folder); - }); + home_folder = await this.currentUser.user.getHomeFolder(); + inbox_folder = await this.currentUser.user.getInboxFolder(); + app_controller.set('home_folder', home_folder); + app_controller.set('inbox_folder', inbox_folder); } } diff --git a/app/components/breadcrumb/index.hbs b/app/components/breadcrumb/index.hbs index cc88a5f..badd252 100644 --- a/app/components/breadcrumb/index.hbs +++ b/app/components/breadcrumb/index.hbs @@ -6,7 +6,15 @@ @node={{node}} @extranode={{@extranode}} @extradoc={{@extradoc}} - @hint={{@hint}} /> + @hint={{@hint}}> + {{#if (is_equal node.title ".inbox")}} + <i class="bi-inbox-fill me-2"></i>Inbox + {{else if (is_equal node.title ".home")}} + <i class="fa fa-home me-2"></i>Home + {{else}} + {{node.title}} + {{/if}} + </DualLinkTo> </li> {{/each}} </ol> diff --git a/app/components/dual_link_to/index.hbs b/app/components/dual_link_to/index.hbs index 735bce8..c60f688 100644 --- a/app/components/dual_link_to/index.hbs +++ b/app/components/dual_link_to/index.hbs @@ -3,5 +3,9 @@ @model={{this.model.id}} @query={{this.query}} ...attributes > - {{this.title}} + {{#if (has-block)}} + {{yield}} + {{else}} + {{this.title}} + {{/if}} </LinkTo> diff --git a/app/components/nav/sidebar.hbs b/app/components/nav/sidebar.hbs index 39e73bb..b382bf4 100644 --- a/app/components/nav/sidebar.hbs +++ b/app/components/nav/sidebar.hbs @@ -12,20 +12,22 @@ </LinkTo> <hr> <ul class="nav nav-pills flex-column mb-auto"> - <li class="nav-item"> + <li> <LinkTo @route="authenticated.nodes" @model="{{@home_folder.id}}" - class="nav-link text-white {{this.active}}" aria-current="page"> + class="nav-link text-white" aria-current="page"> <i class="fa fa-home me-2"></i>Home </LinkTo> </li> <li> - <LinkTo @route="authenticated.inbox" class="nav-link text-white"> + <LinkTo + @route="authenticated.nodes" + @model="{{@inbox_folder.id}}" + class="nav-link text-white" aria-current="page"> <i class="bi-inbox me-2"></i>Inbox </LinkTo> </li> - <li> <LinkTo @route="authenticated.automates" class="nav-link text-white"> <i class="fas fa-robot me-2"></i>Automates @@ -71,13 +73,14 @@ @route="authenticated.nodes" @model="{{@home_folder.id}}" {{tooltip title="Home"}} - class="nav-link text-white {{this.active}}" aria-current="page"> + class="nav-link text-white"> <i class="fa fa-home me-2"></i> </LinkTo> </li> <li> <LinkTo - @route="authenticated.inbox" + @route="authenticated.nodes" + @model="{{@inbox_folder.id}}" {{tooltip title="Inbox"}} class="nav-link text-white" > <i class="bi-inbox me-2"></i> diff --git a/app/components/nav/sidebar.js b/app/components/nav/sidebar.js deleted file mode 100644 index 909b31e..0000000 --- a/app/components/nav/sidebar.js +++ /dev/null @@ -1,31 +0,0 @@ -import Component from '@glimmer/component'; -import { inject as service } from '@ember/service'; - - -export default class SidebarComponent extends Component { - @service router; - - get active() { - /* - Returns 'active' if current route name is one of following: - - * authenticated.nodes - * authenticated.document - - 'active' is used as css class name in component's template. - */ - let route_name, active_routes; - - active_routes = [ - 'authenticated.nodes', - 'authenticated.document', - ] - route_name = this.router.currentRoute.name; - - if (active_routes.includes(route_name)) { - return 'active'; - } - - return ''; - } -} diff --git a/app/controllers/authenticated.js b/app/controllers/authenticated.js index ca5061a..516dc6f 100644 --- a/app/controllers/authenticated.js +++ b/app/controllers/authenticated.js @@ -9,6 +9,5 @@ export default class AuthenticatedController extends Controller { @action onSidebarToggle() { this.expanded = !this.expanded; - console.log(`this.expanded=${this.expanded}`); } } \ No newline at end of file diff --git a/app/models/user.js b/app/models/user.js index 38cc8c2..48beb36 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -31,6 +31,15 @@ class UserModel extends Model { return adapter.getFolder(home_id); } + + async getInboxFolder() { + let inbox_id, adapter; + + adapter = this.store.adapterFor('node'); + inbox_id = this.inbox_folder.get('id'); + + return adapter.getFolder(inbox_id); + } } export default UserModel; diff --git a/app/router.js b/app/router.js index c9e0b99..3c6432e 100644 --- a/app/router.js +++ b/app/router.js @@ -9,7 +9,6 @@ export default class Router extends EmberRouter { Router.map(function () { this.route('authenticated', { path: '' }, function () { this.route('documents'); - this.route('inbox'); this.route('document', { path: '/document/:document_id' }); this.route('nodes', { path: '/nodes/:node_id' }); diff --git a/app/routes/application.js b/app/routes/application.js index 67af593..a23748b 100644 --- a/app/routes/application.js +++ b/app/routes/application.js @@ -1,17 +1,6 @@ import BaseRoute from 'papermerge/base/routing'; -import { service } from '@ember/service'; export default class ApplicationRoute extends BaseRoute { - @service currentUser; - async model() { - if (this.currentUser.isAuthenticated) { - return this.currentUser.user.getHomeFolder(); - } - } - - setupController(controller, model) { - controller.set('home_folder', model); - } } diff --git a/app/routes/authenticated/nodes.js b/app/routes/authenticated/nodes.js index 8ac6978..a4c022e 100644 --- a/app/routes/authenticated/nodes.js +++ b/app/routes/authenticated/nodes.js @@ -4,7 +4,7 @@ import { inject as service } from '@ember/service'; import { getPanelInfo } from './utils'; -export default class FolderRoute extends Route { +export default class NodesRoute extends Route { @service store; @service currentUser; @@ -53,6 +53,8 @@ export default class FolderRoute extends Route { 'pages': extra_pages_with_url, } context['home_folder'] = this.currentUser.user.home_folder; + context['inbox_folder'] = this.currentUser.user.inbox_folder; + return context; } @@ -66,6 +68,7 @@ export default class FolderRoute extends Route { } context['home_folder'] = await this.currentUser.user.getHomeFolder(); + context['inbox_folder'] = await this.currentUser.user.getInboxFolder(); return context; } @@ -75,6 +78,7 @@ export default class FolderRoute extends Route { let _auth_controller = this.controllerFor('authenticated'); _auth_controller.set('home_folder', model.home_folder); + _auth_controller.set('inbox_folder', model.inbox_folder); } } diff --git a/app/templates/authenticated.hbs b/app/templates/authenticated.hbs index 9e784da..6f5d721 100644 --- a/app/templates/authenticated.hbs +++ b/app/templates/authenticated.hbs @@ -1,8 +1,8 @@ <main> <Nav::Sidebar @home_folder={{this.home_folder}} - @expanded={{this.expanded}} - /> + @inbox_folder={{this.inbox_folder}} + @expanded={{this.expanded}} /> <div class="w-100 central-bar"> <Nav::Topbar @onSidebarToggle={{this.onSidebarToggle}} /> diff --git a/app/templates/authenticated/inbox.hbs b/app/templates/authenticated/inbox.hbs deleted file mode 100644 index 1ac28e9..0000000 --- a/app/templates/authenticated/inbox.hbs +++ /dev/null @@ -1 +0,0 @@ -<h1>Inbox</h1> \ No newline at end of file -- GitLab