diff --git a/app/controllers/application.js b/app/controllers/application.js index c4e2f7a5..e4dce963 100644 --- a/app/controllers/application.js +++ b/app/controllers/application.js @@ -1,47 +1,12 @@ -import { computed } from '@ember/object'; import { inject as service } from '@ember/service'; import Controller from '@ember/controller'; -import ObjectProxy from '@ember/object/proxy'; -import PromiseProxyMixin from '@ember/object/promise-proxy-mixin'; -let ObjectPromiseProxy = ObjectProxy.extend(PromiseProxyMixin); - export default Controller.extend({ sidebar: service(), session: service(), store: service(), userSocket: service(), - userCount: computed('userSocket.present.length', function () { - const count = this.get('userSocket.present.length'); - - if (count > 1) { - return count; - } else { - return undefined; - } - }), - - postsRequest: computed(function () { - return ObjectPromiseProxy.create({ - promise: this.get('store').findAll('post').then(posts => { - return { - posts - }; - }) - }); - }), - - unreadCount: computed('postsRequest.posts.@each.unread', function () { - let posts = this.get('postsRequest.posts') - - if (posts) { - return posts.filterBy('unread').length; - } else { - return 0; - } - }), - actions: { logout() { this.get('session').invalidate(); diff --git a/app/services/sidebar.js b/app/services/sidebar.js index 9f44b843..f1eaa777 100644 --- a/app/services/sidebar.js +++ b/app/services/sidebar.js @@ -1,5 +1,48 @@ import Service from '@ember/service'; +import { inject as service } from '@ember/service'; +import { computed } from '@ember/object'; + +import ObjectProxy from '@ember/object/proxy'; +import PromiseProxyMixin from '@ember/object/promise-proxy-mixin'; +let ObjectPromiseProxy = ObjectProxy.extend(PromiseProxyMixin); export default Service.extend({ - open: false + store: service(), + userSocket: service(), + + open: false, + + userCount: computed('userSocket.present.length', function () { + const count = this.get('userSocket.present.length'); + + if (count > 1) { + return count; + } else { + return 0; + } + }), + + postsRequest: computed(function () { + return ObjectPromiseProxy.create({ + promise: this.get('store').findAll('post').then(posts => { + return { + posts + }; + }) + }); + }), + + unreadCount: computed('postsRequest.posts.@each.unread', function () { + let posts = this.get('postsRequest.posts') + + if (posts) { + return posts.filterBy('unread').length; + } else { + return 0; + } + }), + + notificationCount: computed('userCount', 'unreadCount', function() { + return this.get('userCount') + this.get('unreadCount'); + }), }); diff --git a/app/styles/app.scss b/app/styles/app.scss index 20ef6dec..8e7c8afd 100644 --- a/app/styles/app.scss +++ b/app/styles/app.scss @@ -58,6 +58,19 @@ md-toolbar { box-shadow: none; } } + + .count { + border-radius: 10px; + background: white; + color: color($color-indigo, '600'); + font-size: 50%; + text-align: center; + width: 12px; + height: 12px; + position: absolute; + top: 10px; + left: 32px; + } } md-sidenav { diff --git a/app/templates/application.hbs b/app/templates/application.hbs index facac388..57cf095c 100644 --- a/app/templates/application.hbs +++ b/app/templates/application.hbs @@ -47,13 +47,13 @@ {{#paper-item}} {{#link-to 'log'}} Log - {{#if unreadCount}}{{unreadCount}}{{/if}} + {{#if sidebar.unreadCount}}{{sidebar.unreadCount}}{{/if}} {{/link-to}} {{/paper-item}} {{#paper-item}} {{#link-to 'users'}} Users - {{#if userCount}}{{userCount}}{{/if}} + {{#if sidebar.userCount}}{{sidebar.userCount}}{{/if}} {{/link-to}} {{/paper-item}} {{paper-divider}} diff --git a/app/templates/components/toolbar-header.hbs b/app/templates/components/toolbar-header.hbs index e417e99a..a9f41971 100644 --- a/app/templates/components/toolbar-header.hbs +++ b/app/templates/components/toolbar-header.hbs @@ -3,6 +3,9 @@ {{#paper-button iconButton=true onClick=(action 'toggleSidebar') class='hide-gt-sm'}} {{paper-icon "menu"}} {{/paper-button}} + {{#if sidebar.notificationCount}} + {{sidebar.notificationCount}} + {{/if}}

{{title}}

{{#paper-chips readOnly=true content=chips as |item|}}{{item.label}}{{/paper-chips}}