Settings page

pull/326/head
Marcelo Schmidt 11 years ago
parent 73189170a9
commit 0630c8cd8f
  1. 5
      client/routes/router.coffee
  2. 1
      client/views/app/sideNav/privateGroups.coffee
  3. 6
      client/views/app/sideNav/sideNav.coffee
  4. 5
      client/views/app/sideNav/sideNav.html
  5. 26
      client/views/settings/settings.coffee
  6. 221
      client/views/settings/settings.html
  7. 18
      client/views/settings/settingsFlex.coffee
  8. 18
      client/views/settings/settingsFlex.html
  9. 15
      packages/rocketchat-lib/settings/lib/rocketchat.coffee
  10. 14
      packages/rocketchat-lib/settings/server/methods.coffee

@ -10,6 +10,8 @@ FlowRouter.subscriptions = ->
if Meteor.userId()?
@register 'userData', Meteor.subscribe('userData')
@register 'activeUsers', Meteor.subscribe('activeUsers')
if Meteor.user()?.admin
@register 'admin-settings', Meteor.subscribe('admin-settings')
FlowRouter.route '/',
@ -37,9 +39,6 @@ FlowRouter.route '/home',
FlowRouter.route '/settings/:group?',
name: 'settings'
subscriptions: (params, queryParams) ->
@register 'admin-settings', Meteor.subscribe('admin-settings')
action: ->
FlowLayout.render 'main', {center: 'settings'}

@ -9,4 +9,3 @@ Template.privateGroups.events
'click .add-room': (e, instance) ->
SideNav.setFlex "privateGroupsFlex"
SideNav.openFlex()
console.log Template.privateGroupsFlex.onCreated.instance

@ -1,4 +1,6 @@
Template.sideNav.helpers
isAdmin: ->
return Meteor.user()?.admin is true
flexTemplate: ->
return SideNav.getFlex().template
flexData: ->
@ -17,5 +19,9 @@ Template.sideNav.events
'mouseleave .header': ->
SideNav.leaveArrow()
'click .open-settings': ->
SideNav.setFlex "settingsFlex"
SideNav.openFlex()
Template.sideNav.onRendered ->
SideNav.init()

@ -13,6 +13,11 @@
<h3>
<a href="{{pathFor 'privateHistory'}}">{{_ "History"}}</a>
</h3>
{{#if isAdmin}}
<h3 class="open-settings">
{{_ "App_Settings"}}
</h3>
{{/if}}
</div>
</div>
<div class="flex-nav hidden">

@ -18,6 +18,8 @@ Template.settings.helpers
return 'left' unless Session.equals('flexOpened', true)
label: ->
return TAPi18next.t @i18nLabel
description: ->
return TAPi18next.t @i18nDescription
Template.settings.events
"click .burger": ->
@ -27,11 +29,21 @@ Template.settings.events
else
chatContainer.addClass("menu-closed").removeClass("menu-opened")
"click .flex-tab .more": (event) ->
console.log 'settings click .flex-tab .more' if window.rocketDebug
Session.set('flexOpened', !Session.get('flexOpened'))
"click .submit": ->
group = FlowRouter.getParam('group')
settings = Settings.find({ group: group }).fetch()
updateSettings = []
for setting in settings
value = null
if setting.type is 'string'
value = _.trim($("input[name=#{setting._id}]").val())
else if setting.type is 'boolean' and $("input[name=#{setting._id}]:checked").length
value = if $("input[name=#{setting._id}]:checked").val() is "1" then true else false
Template.settings.onRendered ->
console.log 'room.onRendered' if window.rocketDebug
Session.set 'flexOpened', true
FlexTab.check()
if value?
updateSettings.push { _id: setting._id, value: value }
if not _.isEmpty updateSettings
RocketChat.settings.batchSet updateSettings, (err, success) ->
return toastr.error TAPi18next.t 'Error_updating_settings' if err
toastr.success TAPi18next.t 'Settings_updated'

@ -1,61 +1,210 @@
<template name="settings">
<section class="page-container page-home page-static">
<head class="fixed-title">
<div>
<div class="burger">
<i></i>
<i></i>
<i></i>
</div>
<h2>
<span class="room-title">{{_ "App_Settings"}}</span>
</h2>
<div class="burger">
<i></i>
<i></i>
<i></i>
</div>
<h2>
<span class="room-title">{{_ "App_Settings"}}</span>
</h2>
</head>
<div class="content">
{{#unless isAdmin}}
<p>You are not authorized to view this page.</p>
{{else}}
<h3>{{label}}</h3>
<div class="info">
{{#with group}}
<h3>{{label}}</h3>
<h3>{{description}}</h3>
{{/with}}
</div>
<div class="rocket-form">
<fieldset>
{{#each settings}}
{{#if $eq type 'string'}}
<div class="input-line double-col">
<label>{{label}}</label>
<div>
<input type="text" name="{{_id}}" value="{{value}}" />
</div>
</div>
{{/if}}
{{#if $eq type 'boolean'}}
<div class="input-line double-col">
<label>{{label}}</label>
<div>
<label><input type="radio" name="{{_id}}" value="1" checked="{{$eq value true}}" /> {{_ "True"}}</label>
<label><input type="radio" name="{{_id}}" value="0" checked="{{$eq value false}}" /> {{_ "False"}}</label>
</div>
</div>
{{/if}}
{{/each}}
</fieldset>
{{!-- <fieldset>
<legend>
<!-- <h3>This is another section</h3>
<p>This is a configuration text. With configuration info</p> -->
<h3>This is another section</h3>
<p>This is a configuration text. With configuration info</p>
</legend>
{{#each settings}}
<div class="input-line double-col">
<label>{{label}}</label>
<label>Input Field</label>
<div>
<input type="text" name="input-name" value="{{value}}" />
<input type="text" name="input-name" />
</div>
</div>
<div class="input-line double-col">
<label>Select Field</label>
<div>
<select name="select">
<option value="1">Option A</option>
<option value="1">Option B</option>
<option value="1">Option C</option>
<option value="1">Option D</option>
<option value="1">Option E</option>
</select>
</div>
</div>
</fieldset>
<fieldset>
<legend>
<h3>This is another section</h3>
<p>This is a configuration text. With configuration info</p>
</legend>
<div class="input-line double-col">
<label>Radio field</label>
<div>
<label><input type="radio" name="pandora" value="1" /> Calazar</label>
<label><input type="radio" name="pandora" value="2" /> Genoveve</label>
</div>
</div>
<div class="input-line double-col">
<label>Checkbox field</label>
<div>
<label><input type="checkbox" name="pandora" value="1" /> Calazar</label>
<label><input type="checkbox" name="pandora" value="2" /> Genoveve</label>
</div>
</div>
{{/each}}
</fieldset>
<fieldset>
<legend>
<h3>This is another section</h3>
<p>This is a configuration text. With configuration info</p>
</legend>
<div class="input-line double-col">
<label>Input Field</label>
<div>
<input type="text" name="input-name" />
</div>
</div>
<div class="input-line double-col">
<label>Select Field</label>
<div>
<select name="select">
<option value="1">Option A</option>
<option value="1">Option B</option>
<option value="1">Option C</option>
<option value="1">Option D</option>
<option value="1">Option E</option>
</select>
</div>
</div>
</fieldset> --}}
<div class="submit">
<button class="button"><i class="icon-send"></i><span>{{_ "Save_changes"}}</span></button>
</div>
</div>
{{/unless}}
</div>
</section>
{{#if isAdmin}}
<section class="flex-tab">
<div class="control">
<button class="more"><span class="arrow {{arrowPosition}}"></span></button>
<div class="search-form">
<div class="input-line search">
<input type="text" class="search" placeholder={{_ "Search_settings"}} />
<i class="icon-plus"></i>
{{!-- <section class="page-container page-home page-static">
<header class="fixed-title">
<div class="burger">
<i></i>
<i></i>
<i></i>
</div>
<h2>
<span class="room-title">{{_ "App_Settings"}}</span>
</h2>
</header>
<div class="content">
<div class="info">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
</div>
<div class="rocket-form">
<fieldset>
<legend>
<h3>This is another section</h3>
<p>This is a configuration text. With configuration info</p>
</legend>
<div class="input-line double-col">
<label>Input Field</label>
<div>
<input type="text" name="input-name" />
</div>
</div>
<div class="input-line double-col">
<label>Select Field</label>
<div>
<select name="select">
<option value="1">Option A</option>
<option value="1">Option B</option>
<option value="1">Option C</option>
<option value="1">Option D</option>
<option value="1">Option E</option>
</select>
</div>
</div>
</fieldset>
<fieldset>
<legend>
<h3>This is another section</h3>
<p>This is a configuration text. With configuration info</p>
</legend>
<div class="input-line double-col">
<label>Radio field</label>
<div>
<label><input type="radio" name="pandora" value="1" /> Calazar</label>
<label><input type="radio" name="pandora" value="2" /> Genoveve</label>
</div>
</div>
<div class="input-line double-col">
<label>Checkbox field</label>
<div>
<label><input type="checkbox" name="pandora" value="1" /> Calazar</label>
<label><input type="checkbox" name="pandora" value="2" /> Genoveve</label>
</div>
</div>
</fieldset>
<fieldset>
<legend>
<h3>This is another section</h3>
<p>This is a configuration text. With configuration info</p>
</legend>
<div class="input-line double-col">
<label>Input Field</label>
<div>
<input type="text" name="input-name" />
</div>
</div>
<div class="input-line double-col">
<label>Select Field</label>
<div>
<select name="select">
<option value="1">Option A</option>
<option value="1">Option B</option>
<option value="1">Option C</option>
<option value="1">Option D</option>
<option value="1">Option E</option>
</select>
</div>
</div>
</fieldset>
<div class="submit">
<button class="button"><i class="icon-send"></i><span>Save changes</span></button>
</div>
</div>
<div class="content">
<ul class='list cf_ lines'>
{{#each groups}}
<li>
<a href="{{pathFor 'settings' group=_id}}">{{_ i18nLabel}}</a>
</li>
{{/each}}
</ul>
</div>
</section>
{{/if}}
</template>
</div>
</section> --}}
</template>

@ -0,0 +1,18 @@
Template.settingsFlex.helpers
groups: ->
return Settings.find({type: 'group'}).fetch()
label: ->
return TAPi18next.t @i18nLabel
Template.settingsFlex.events
'mouseenter header': ->
SideNav.overArrow()
'mouseleave header': ->
SideNav.leaveArrow()
'click header': ->
SideNav.closeFlex()
'click .cancel-settings': ->
SideNav.closeFlex()

@ -0,0 +1,18 @@
<template name="settingsFlex">
<header>
<div>
<h4>{{_ "Settings"}}</h4>
</div>
</header>
<div class="content">
<div class="wrapper">
<ul>
{{#each groups}}
<li>
<a href="{{pathFor 'settings' group=_id}}">{{_ i18nLabel}}</a>
</li>
{{/each}}
</ul>
</div>
</div>
</template>

@ -6,3 +6,18 @@ RocketChat.settings = {}
RocketChat.settings.get = (_id) ->
return Meteor.settings?[_id]
RocketChat.settings.set = (_id, value, callback) ->
Meteor.call 'saveSetting', _id, value, callback
RocketChat.settings.batchSet = (settings, callback) ->
# async -> sync
# http://daemon.co.za/2012/04/simple-async-with-only-underscore/
save = (setting) ->
return (callback) ->
Meteor.call 'saveSetting', setting._id, setting.value, callback
actions = _.map settings, (setting) -> save(setting)
_(actions).reduceRight(_.wrap, (err, success) -> return callback err, success)()

@ -16,6 +16,7 @@ RocketChat.settings.add = (_id, value, options = {}) ->
updateSettings =
i18nLabel: options.i18nLabel or _id
i18nDescription: options.i18nDescription if options.i18nDescription?
updateSettings.type = options.type if options.type
updateSettings.group = options.group if options.group
@ -36,6 +37,19 @@ RocketChat.settings.addGroup = (_id, options = {}) ->
updateSettings =
i18nLabel: options.i18nLabel or _id
i18nDescription: options.i18nDescription if options.i18nDescription?
type: 'group'
return Settings.upsert { _id: _id }, { $set: updateSettings }
Meteor.methods
saveSetting: (_id, value) ->
if Meteor.userId()?
user = Meteor.users.findOne Meteor.userId()
unless user?.admin is true
throw new Meteor.Error 503, 'Not authorized'
console.log "saveSetting -> ".green, _id, value
Settings.update { _id: _id }, { $set: { value: value } }
return true
Loading…
Cancel
Save