Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Service account sidenav type #9

Merged
merged 4 commits into from
Jul 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/api/server/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ API.v1.addRoute('users.setPreferences', { authRequired: true }, {
sidebarHideAvatar: Match.Optional(Boolean),
sidebarGroupByType: Match.Optional(Boolean),
sidebarShowDiscussion: Match.Optional(Boolean),
sidebarShowServiceAccounts: Match.Optional(Boolean),
muteFocusedConversations: Match.Optional(Boolean),
}),
});
Expand Down
3 changes: 3 additions & 0 deletions app/service-accounts/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ import './route';
// views
import './views/serviceAccountDashboard';
import './views/creationDialog/createServiceAccount';
import './views/serviceAccountsList';

import '../lib/serviceAccountRoomType';
import './views/serviceAccountSidebarLogin';
10 changes: 10 additions & 0 deletions app/service-accounts/client/views/serviceAccountsList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template name="serviceAccountsList">
{{#if rooms}}
<h3 class="rooms-list__type">
{{_ "Subscriptions"}}
</h3>
<ul class="rooms-list__list">
{{#each room in rooms}} {{> chatRoomItem room }} {{/each}}
</ul>
{{/if}}
</template>
29 changes: 29 additions & 0 deletions app/service-accounts/client/views/serviceAccountsList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';

import { ChatSubscription } from '../../../models/client';
import { getUserPreference } from '../../../utils/client';
import { settings } from '../../../settings/client';

import './serviceAccountsList.html';

Template.serviceAccountsList.helpers({
rooms() {
const user = Meteor.userId();
const sortBy = getUserPreference(user, 'sidebarSortby') || 'alphabetical';
const query = {
open: true,
};

const sort = {};

if (sortBy === 'activity') {
sort.lm = -1;
} else { // alphabetical
sort[this.identifier === 'd' && settings.get('UI_Use_Real_Name') ? 'lowerCaseFName' : 'lowerCaseName'] = /descending/.test(sortBy) ? -1 : 1;
}

query.sa = { $exists: true };
return ChatSubscription.find(query, { sort });
},
});
22 changes: 22 additions & 0 deletions app/service-accounts/lib/serviceAccountRoomType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Meteor } from 'meteor/meteor';

import { RoomTypeConfig, roomTypes, getUserPreference } from '../../utils';

export class ServiceAccountRoomType extends RoomTypeConfig {
constructor() {
super({
identifier: 'sa',
order: 60,
label: 'Subscriptions',
});

// we need a custom template in order to have a custom query showing the subscriptions to serviceAccounts
this.customTemplate = 'serviceAccountsList';
}

condition() {
return getUserPreference(Meteor.userId(), 'sidebarShowServiceAccounts');
}
}

roomTypes.add(new ServiceAccountRoomType());
7 changes: 7 additions & 0 deletions app/service-accounts/server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ Meteor.startup(() => {
public: true,
});
});
settings.add('Accounts_Default_User_Preferences_sidebarShowServiceAccounts', true, {
group: 'Accounts',
section: 'Accounts_Default_User_Preferences',
type: 'boolean',
public: true,
i18nLabel: 'Group_subscriptions',
});
});
2 changes: 2 additions & 0 deletions app/service-accounts/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ import './hooks/serviceAccountCallback';

import './publications/fullServiceAccountData';
import './publications/userServiceAccounts';

import '../lib/serviceAccountRoomType';
7 changes: 7 additions & 0 deletions app/ui-account/client/accountPreferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ <h1>{{_ "Sidebar"}}</h1>
<label><input type="radio" name="sidebarShowDiscussion" value="false" checked="{{checked 'sidebarShowDiscussion' false}}"/> {{_ "False"}}</label>
</div>
</div>
<div class="input-line double-col" id="sidebarShowServiceAccounts">
<label class="setting-label">{{_ "Group_subscriptions"}}</label>
<div>
<label><input type="radio" name="sidebarShowServiceAccounts" value="true" checked="{{checked 'sidebarShowServiceAccounts' true}}"/> {{_ "True"}}</label>
<label><input type="radio" name="sidebarShowServiceAccounts" value="false" checked="{{checked 'sidebarShowServiceAccounts' false}}"/> {{_ "False"}}</label>
</div>
</div>
</div>
</div>
<div class="section">
Expand Down
1 change: 1 addition & 0 deletions app/ui-account/client/accountPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ Template.accountPreferences.onCreated(function() {
data.mobileNotifications = $('#mobileNotifications').find('select').val();
data.unreadAlert = JSON.parse($('#unreadAlert').find('input:checked').val());
data.sidebarShowDiscussion = JSON.parse($('#sidebarShowDiscussion').find('input:checked').val());
data.sidebarShowServiceAccounts = JSON.parse($('#sidebarShowServiceAccounts').find('input:checked').val());
data.notificationsSoundVolume = parseInt($('#notificationsSoundVolume').val());
data.roomCounterSidebar = JSON.parse($('#roomCounterSidebar').find('input:checked').val());
data.highlights = _.compact(_.map($('[name=highlights]').val().split(/,|\n/), function(e) {
Expand Down
5 changes: 5 additions & 0 deletions app/ui-sidenav/client/roomList.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Template.roomList.helpers({
'settings.preferences.sidebarShowFavorites': 1,
'settings.preferences.sidebarShowUnread': 1,
'settings.preferences.sidebarShowDiscussion': 1,
'settings.preferences.sidebarShowServiceAccounts': 1,
'services.tokenpass': 1,
messageViewMode: 1,
},
Expand Down Expand Up @@ -84,6 +85,10 @@ Template.roomList.helpers({
query.prid = { $exists: false };
}

if (getUserPreference(user, 'sidebarShowServiceAccounts')) {
query.sa = { $exists: false };
}

if (getUserPreference(user, 'sidebarShowUnread')) {
query.$or = [
{ alert: { $ne: true } },
Expand Down
9 changes: 9 additions & 0 deletions app/ui-sidenav/client/sortlist.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
<span class="rc-popover__item-text">{{_ "Group_discussions"}}</span>
</label>
</li>
<li class="rc-popover__item {{bold 'sidebarShowServiceAccounts'}}">
<label class="rc-popover__label">
<input type="checkbox" name="sidebarShowServiceAccounts" class="hidden" checked="{{checked 'sidebarShowServiceAccounts'}}" />
<span class="rc-popover__icon">
{{> icon block="rc-popover__icon-element" icon='user' }}
</span>
<span class="rc-popover__item-text">{{_ "Group_subscriptions"}}</span>
</label>
</li>
<li class="rc-popover__item {{bold 'sidebarGroupByType'}}">
<label class="rc-popover__label">
<input type="checkbox" name="sidebarGroupByType" class="hidden" checked="{{checked 'sidebarGroupByType'}}"/>
Expand Down
3 changes: 3 additions & 0 deletions app/ui-sidenav/client/sortlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const checked = function(prop, field) {
if (prop === 'sidebarShowDiscussion') {
return getUserPreference(userId, 'sidebarShowDiscussion');
}
if (prop === 'sidebarShowServiceAccounts') {
return getUserPreference(userId, 'sidebarShowServiceAccounts');
}
if (prop === 'sidebarShowFavorites') {
return getUserPreference(userId, 'sidebarShowFavorites');
}
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,7 @@
"Group_favorites": "Group favorites",
"Group_mentions_disabled_x_members": "Group mentions `@all` and `@here` have been disabled for rooms with more than __total__ members.",
"Group_mentions_only": "Group mentions only",
"Group_subscriptions": "Group subscriptions",
"Guest_Pool": "Guest Pool",
"Hash": "Hash",
"Header": "Header",
Expand Down
1 change: 1 addition & 0 deletions server/methods/saveUserPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Meteor.methods({
sidebarHideAvatar: Match.Optional(Boolean),
sidebarGroupByType: Match.Optional(Boolean),
sidebarShowDiscussion: Match.Optional(Boolean),
sidebarShowServiceAccounts: Match.Optional(Boolean),
muteFocusedConversations: Match.Optional(Boolean),
};
check(settings, Match.ObjectIncluding(keys));
Expand Down
1 change: 1 addition & 0 deletions server/publications/subscription/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const fields = {
roles: 1,
unread: 1,
prid: 1,
sa: 1,
userMentions: 1,
groupMentions: 1,
archived: 1,
Expand Down
1 change: 1 addition & 0 deletions tests/end-to-end/api/00-miscellaneous.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ describe('miscellaneous', function() {
'sidebarGroupByType',
'muteFocusedConversations',
'sidebarShowDiscussion',
'sidebarShowServiceAccounts',
];

expect(res.body).to.have.property('success', true);
Expand Down