Skip to content

Commit

Permalink
Tabbed user interface for custom room types creation
Browse files Browse the repository at this point in the history
Addresses RocketChat#8264
  • Loading branch information
mrsimpson committed Oct 6, 2017
1 parent b2a425f commit 3459fa8
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 37 deletions.
2 changes: 2 additions & 0 deletions packages/rocketchat-lib/lib/roomTypesCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ this.roomTypesCommon = class {
name: route name
action: route action function
identifier: room type identifier
creationTemplate: The blaze template which shall be used in the create-dialog
creationLabel: The hreadline of the creation dialog
Optional methods which can be redefined
getDisplayName(room): return room's name for the UI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
}

&__back-text {
z-index: 100;
margin-right: 2px;

line-height: 22px;
}

&__back-icon {
z-index: 100;
transform: rotate(45deg);

font-size: 1rem;
}
}
Expand Down
77 changes: 77 additions & 0 deletions packages/rocketchat-theme/client/imports/components/tab.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
.rc-tabs {
position: relative;

display: flex;

margin: 0 calc(var(--tabs-padding) / -2);
padding: calc(var(--tabs-padding) / 2);

list-style: none;

color: var(--color-gray);

font-size: 14px;

&::before {
position: absolute;
bottom: 0;

width: 100%;
height: 2px;

content: '';

background: var(--color-gray-light);
}

&__tab {
position: relative;

margin: calc(var(--tabs-padding) / 2);
padding: 0 5px;

cursor: pointer;
transition: all 0.3s;

&-link {
color: inherit !important;
}

&:hover {
opacity: 0.5;
}

&.active,
&:active {
color: #1d74f5;

&::before {
position: absolute;
bottom: calc(var(--tabs-padding) * -1);
left: 0;

width: 100%;
height: 2px;

content: '';

background: #1d74f5;
}
}
}

&__content {
padding-top: 10px;
& header h1 { /* in tab-containers, the first heading of the header is the tab strip itself */
display: none;
}

&.inactive {
display: none;
}

&.active {
display: block;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,9 @@
--message-box-editing-color: #fff5df;
--message-box-popover-title-text-color: var(--color-gray);
--message-box-popover-title-text-size: 0.75rem;

/*
* Tabs
*/
--tabs-padding: 1rem;
}
4 changes: 4 additions & 0 deletions packages/rocketchat-theme/client/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@

/* RTL */
@import 'imports/general/rtl.css';

/* tabs */
@import 'imports/components/tab.css';

19 changes: 19 additions & 0 deletions packages/rocketchat-ui/client/components/tabContainer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<template name="tabContainer">
<div class="rc-tabs__container">
<nav class="rc-tabs">
{{#each tab in tabs}}
<li class="rc-tabs__tab {{activeClass tab.template}}">
<a class="rc-tabs__tab-link" href="#{{tab.template}}">
{{_ tab.label}}
</a>
</li>
{{/each}}
</nav>

{{#each tab in tabs}}
<div class="rc-tabs__content {{activeClass tab.template}}">
{{> Template.dynamic template=tab.template }}
</div>
{{/each}}
</div>
</template>
18 changes: 18 additions & 0 deletions packages/rocketchat-ui/client/components/tabContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Template.tabContainer.helpers({
activeClass(templateName) {
const instance = Template.instance();
return instance.activeTemplate.get() === templateName ? 'active' : 'inactive';
},
});

Template.tabContainer.events({
'click .rc-tabs__tab-link'(event, instance) {
event.preventDefault();
const tmp = event.target.href.split('#');
instance.activeTemplate.set(tmp[tmp.length - 1]);
}
});

Template.tabContainer.onCreated(function(){
this.activeTemplate = new ReactiveVar(this.data.tabs[0].template);
});
12 changes: 0 additions & 12 deletions packages/rocketchat-ui/client/views/app/createChannel.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<template name="createChannel">
<section class="create-channel">
{{#each roomType in roomTypesBeforeStandard}}
<div class="room-type-creation">
{{> Template.dynamic template=roomType.creationTemplate }}
</div>
{{/each}}
<div class="room-type-creation">
<header class="create-channel__header">
<h1 class="create-channel__title">{{_ "Create_A_New_Channel"}}</h1>
Expand Down Expand Up @@ -89,12 +83,6 @@ <h1 class="create-channel__title">{{_ "Create_A_New_Channel"}}</h1>
value="{{_ "Create"}}">
</form>
</div>
{{#each roomType in roomTypesAfterStandard}}
<div class="room-type-creation">
{{> Template.dynamic template=roomType.creationTemplate }}
</div>
{{/each}}
</section>
</template>

<template name='tag'>
Expand Down
20 changes: 0 additions & 20 deletions packages/rocketchat-ui/client/views/app/createChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,6 @@ Template.createChannel.helpers({
},
iconType() {
return Template.instance().type.get() === 'p' ? 'lock' : 'hashtag';
},
roomTypesBeforeStandard() {
const orderLow = RocketChat.roomTypes.roomTypesOrder.filter((roomTypeOrder) => roomTypeOrder.identifier === 'c')[0].order;
return RocketChat.roomTypes.roomTypesOrder.filter(
(roomTypeOrder) => roomTypeOrder.order < orderLow
).map(
(roomTypeOrder) => {
return RocketChat.roomTypes.roomTypes[roomTypeOrder.identifier];
}
).filter((roomType) => roomType.creationTemplate);
},
roomTypesAfterStandard() {
const orderHigh = RocketChat.roomTypes.roomTypesOrder.filter((roomTypeOrder) => roomTypeOrder.identifier === 'd')[0].order;
return RocketChat.roomTypes.roomTypesOrder.filter(
(roomTypeOrder) => roomTypeOrder.order > orderHigh
).map(
(roomTypeOrder) => {
return RocketChat.roomTypes.roomTypes[roomTypeOrder.identifier];
}
).filter((roomType) => roomType.creationTemplate);
}
});

Expand Down
10 changes: 10 additions & 0 deletions packages/rocketchat-ui/client/views/app/createRooms.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template name="createRooms">
<section class="create-channel">
{{#if tabsNeeded }}
{{> tabContainer tabs=tabs}}
{{else}}
{{> createChannel }}
{{/if}}
</section>

</template>
48 changes: 48 additions & 0 deletions packages/rocketchat-ui/client/views/app/createRooms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const roomTypesBeforeStandard = function() {
const orderLow = RocketChat.roomTypes.roomTypesOrder.filter((roomTypeOrder) => roomTypeOrder.identifier === 'c')[0].order;
return RocketChat.roomTypes.roomTypesOrder.filter(
(roomTypeOrder) => roomTypeOrder.order < orderLow
).map(
(roomTypeOrder) => {
return RocketChat.roomTypes.roomTypes[roomTypeOrder.identifier];
}
).filter((roomType) => roomType.creationTemplate);
};
const roomTypesAfterStandard = function() {
const orderHigh = RocketChat.roomTypes.roomTypesOrder.filter((roomTypeOrder) => roomTypeOrder.identifier === 'd')[0].order;
return RocketChat.roomTypes.roomTypesOrder.filter(
(roomTypeOrder) => roomTypeOrder.order > orderHigh
).map(
(roomTypeOrder) => {
return RocketChat.roomTypes.roomTypes[roomTypeOrder.identifier];
}
).filter((roomType) => roomType.creationTemplate);
};

const allTemplatesOrdered = function() {
return roomTypesBeforeStandard()
.concat([{
creationLabel: 'Create_A_New_Channel',
creationTemplate: 'createChannel'
}])
.concat(roomTypesAfterStandard())
.map((roomtype) => {
return {
label: roomtype.creationLabel,
template: roomtype.creationTemplate
};
});
};

Template.createRooms.helpers({
tabsNeeded() {
const instance = Template.instance();
return !!(instance.data.roomTypesBeforeStandard.length || instance.data.roomTypesAfterStandard.length);
}
});

Template.createRooms.onCreated(function() {
this.data.roomTypesBeforeStandard = roomTypesBeforeStandard();
this.data.roomTypesAfterStandard = roomTypesAfterStandard();
this.data.tabs = allTemplatesOrdered();
});
4 changes: 2 additions & 2 deletions packages/rocketchat-ui/client/views/app/fullModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ FlowRouter.route('/create-channel', {

action() {
if (parent) {
Blaze.renderWithData(Template.fullModal, {template: 'createChannel'}, parent);
Blaze.renderWithData(Template.fullModal, {template: 'createRooms'}, parent);
} else {
BlazeLayout.render('main', {center: 'fullModal', template: 'createChannel'});
BlazeLayout.render('main', {center: 'fullModal', template: 'createRooms'});
}
},

Expand Down
5 changes: 4 additions & 1 deletion packages/rocketchat-ui/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Package.onUse(function(api) {
api.addFiles('client/views/app/audioNotification.html', 'client');
api.addFiles('client/views/app/burger.html', 'client');
api.addFiles('client/views/app/createChannel.html', 'client');
api.addFiles('client/views/app/createRooms.html', 'client');
api.addFiles('client/views/app/fullModal.html', 'client');
api.addFiles('client/views/app/home.html', 'client');
api.addFiles('client/views/app/notAuthorized.html', 'client');
Expand All @@ -107,6 +108,7 @@ Package.onUse(function(api) {
api.addFiles('client/views/404/roomNotFound.js', 'client');
api.addFiles('client/views/app/burger.js', 'client');
api.addFiles('client/views/app/createChannel.js', 'client');
api.addFiles('client/views/app/createRooms.js', 'client');
api.addFiles('client/views/app/fullModal.js', 'client');
api.addFiles('client/views/app/home.js', 'client');
api.addFiles('client/views/app/mobileMessageMenu.js', 'client');
Expand All @@ -127,7 +129,8 @@ Package.onUse(function(api) {
api.addFiles('client/components/selectDropdown.html', 'client');
api.addFiles('client/components/selectDropdown.js', 'client');


api.addFiles('client/components/tabContainer.html', 'client');
api.addFiles('client/components/tabContainer.js', 'client');

api.export('fileUpload');
});

0 comments on commit 3459fa8

Please sign in to comment.