From 0b986ed3147c885af6b2f33e1ff3eb6754e8f274 Mon Sep 17 00:00:00 2001
From: =Corey Hulen <corey@hulen.com>
Date: Mon, 11 Jan 2016 12:31:13 -0600
Subject: Adding UI

---
 .../user_settings/manage_command_hooks.jsx         | 260 +++++++++++++++++++++
 1 file changed, 260 insertions(+)
 create mode 100644 web/react/components/user_settings/manage_command_hooks.jsx

(limited to 'web/react/components/user_settings/manage_command_hooks.jsx')

diff --git a/web/react/components/user_settings/manage_command_hooks.jsx b/web/react/components/user_settings/manage_command_hooks.jsx
new file mode 100644
index 000000000..375ccb33f
--- /dev/null
+++ b/web/react/components/user_settings/manage_command_hooks.jsx
@@ -0,0 +1,260 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import LoadingScreen from '../loading_screen.jsx';
+
+import * as Client from '../../utils/client.jsx';
+
+export default class ManageCommandHooks extends React.Component {
+    constructor() {
+        super();
+
+        this.getHooks = this.getHooks.bind(this);
+        this.addNewHook = this.addNewHook.bind(this);
+        this.updateTrigger = this.updateTrigger.bind(this);
+        this.updateURL = this.updateURL.bind(this);
+
+        this.state = {hooks: [], channelId: '', trigger: '', URL: '', getHooksComplete: false};
+    }
+
+    componentDidMount() {
+        this.getHooks();
+    }
+
+    addNewHook(e) {
+        e.preventDefault();
+
+        if (this.state.trigger === '' || this.state.URL === '') {
+            return;
+        }
+
+        const hook = {};
+        if (this.state.trigger.length !== 0) {
+            hook.trigger = this.state.trigger.trim();
+        }
+        hook.url = this.state.URL.trim();
+
+        Client.addCommand(
+            hook,
+            (data) => {
+                let hooks = Object.assign([], this.state.hooks);
+                if (!hooks) {
+                    hooks = [];
+                }
+                hooks.push(data);
+                this.setState({hooks, addError: null, triggerWords: '', URL: ''});
+            },
+            (err) => {
+                this.setState({addError: err.message});
+            }
+        );
+    }
+
+    removeHook(id) {
+        const data = {};
+        data.id = id;
+
+        Client.deleteCommand(
+            data,
+            () => {
+                const hooks = this.state.hooks;
+                let index = -1;
+                for (let i = 0; i < hooks.length; i++) {
+                    if (hooks[i].id === id) {
+                        index = i;
+                        break;
+                    }
+                }
+
+                if (index !== -1) {
+                    hooks.splice(index, 1);
+                }
+
+                this.setState({hooks});
+            },
+            (err) => {
+                this.setState({editError: err.message});
+            }
+        );
+    }
+
+    regenToken(id) {
+        const regenData = {};
+        regenData.id = id;
+
+        Client.regenCommandToken(
+            regenData,
+            (data) => {
+                const hooks = Object.assign([], this.state.hooks);
+                for (let i = 0; i < hooks.length; i++) {
+                    if (hooks[i].id === id) {
+                        hooks[i] = data;
+                        break;
+                    }
+                }
+
+                this.setState({hooks, editError: null});
+            },
+            (err) => {
+                this.setState({editError: err.message});
+            }
+        );
+    }
+
+    getHooks() {
+        Client.listCommands(
+            (data) => {
+                if (data) {
+                    this.setState({hooks: data, getHooksComplete: true, editError: null});
+                }
+            },
+            (err) => {
+                this.setState({editError: err.message});
+            }
+        );
+    }
+
+    updateTrigger(e) {
+        this.setState({trigger: e.target.value});
+    }
+
+    updateURL(e) {
+        this.setState({URL: e.target.value});
+    }
+
+    render() {
+        let addError;
+        if (this.state.addError) {
+            addError = <label className='has-error'>{this.state.addError}</label>;
+        }
+
+        let editError;
+        if (this.state.editError) {
+            addError = <label className='has-error'>{this.state.editError}</label>;
+        }
+
+        const hooks = [];
+        this.state.hooks.forEach((hook) => {
+            let triggerDiv;
+            if (hook.trigger && hook.trigger.length !== 0) {
+                triggerDiv = (
+                    <div className='padding-top'>
+                        <strong>{'Trigger: '}</strong>{hook.trigger}
+                    </div>
+                );
+            }
+
+            hooks.push(
+                <div
+                    key={hook.id}
+                    className='webhook__item'
+                >
+                    <div className='padding-top x2 webhook__url'>
+                        <strong>{'URL: '}</strong><span className='word-break--all'>{hook.url}</span>
+                    </div>
+                    {triggerDiv}
+                    <div className='padding-top'>
+                        <strong>{'Token: '}</strong>{hook.token}
+                    </div>
+                    <div className='padding-top'>
+                        <a
+                            className='text-danger'
+                            href='#'
+                            onClick={this.regenToken.bind(this, hook.id)}
+                        >
+                            {'Regen Token'}
+                        </a>
+                        <a
+                            className='webhook__remove'
+                            href='#'
+                            onClick={this.removeHook.bind(this, hook.id)}
+                        >
+                            <span aria-hidden='true'>{'×'}</span>
+                        </a>
+                    </div>
+                    <div className='padding-top x2 divider-light'></div>
+                </div>
+            );
+        });
+
+        let displayHooks;
+        if (!this.state.getHooksComplete) {
+            displayHooks = <LoadingScreen/>;
+        } else if (hooks.length > 0) {
+            displayHooks = hooks;
+        } else {
+            displayHooks = <div className='padding-top x2'>{'None'}</div>;
+        }
+
+        const existingHooks = (
+            <div className='webhooks__container'>
+                <label className='control-label padding-top x2'>{'Existing commands'}</label>
+                <div className='padding-top divider-light'></div>
+                <div className='webhooks__list'>
+                    {displayHooks}
+                </div>
+            </div>
+        );
+
+        const disableButton = this.state.trigger === '' || this.state.URL === '';
+
+        return (
+            <div key='addCommandHook'>
+                {'Create commands to send new message events to an external integration. Please see '}
+                <a
+                    href='http://mattermost.org/commands'
+                    target='_blank'
+                >
+                    {'http://mattermost.org/commands'}
+                </a>
+                {' to learn more.'}
+                <div><label className='control-label padding-top x2'>{'Add a new command'}</label></div>
+                <div className='padding-top divider-light'></div>
+                <div className='padding-top'>
+                    <div className='padding-top x2'>
+                        <label className='control-label'>{'Trigger:'}</label>
+                        <div className='padding-top'>
+                            {'/'}
+                            <input
+                                ref='trigger'
+                                className='form-control'
+                                value={this.state.trigger}
+                                onChange={this.updateTrigger}
+                                placeholder='Command trigger e.g. "hello" not including the slash'
+                            />
+                        </div>
+                        <div className='padding-top'>{'Word to trigger on'}</div>
+                    </div>
+                    <div className='padding-top x2'>
+                        <label className='control-label'>{'Callback URL:'}</label>
+                        <div className='padding-top'>
+                        <textarea
+                            ref='URL'
+                            className='form-control no-resize'
+                            value={this.state.URL}
+                            resize={false}
+                            rows={3}
+                            onChange={this.URL}
+                            placeholder='Must start with http:// or https://'
+                        />
+                        </div>
+                        <div className='padding-top'>{'URL that will receive the HTTP POST or GET event'}</div>
+                        {addError}
+                    </div>
+                    <div className='padding-top padding-bottom'>
+                        <a
+                            className={'btn btn-sm btn-primary'}
+                            href='#'
+                            disabled={disableButton}
+                            onClick={this.addNewHook}
+                        >
+                            {'Add'}
+                        </a>
+                    </div>
+                </div>
+                {existingHooks}
+                {editError}
+            </div>
+        );
+    }
+}
-- 
cgit v1.2.3-1-g7c22


From 586967b757a869dbb5f3677e605009a1f5c61005 Mon Sep 17 00:00:00 2001
From: =Corey Hulen <corey@hulen.com>
Date: Thu, 14 Jan 2016 10:52:14 -0600
Subject: finishing up commands UI

---
 .../user_settings/manage_command_hooks.jsx         | 316 ++++++++++++++++-----
 1 file changed, 249 insertions(+), 67 deletions(-)

(limited to 'web/react/components/user_settings/manage_command_hooks.jsx')

diff --git a/web/react/components/user_settings/manage_command_hooks.jsx b/web/react/components/user_settings/manage_command_hooks.jsx
index 375ccb33f..1fb3bf599 100644
--- a/web/react/components/user_settings/manage_command_hooks.jsx
+++ b/web/react/components/user_settings/manage_command_hooks.jsx
@@ -5,44 +5,66 @@ import LoadingScreen from '../loading_screen.jsx';
 
 import * as Client from '../../utils/client.jsx';
 
-export default class ManageCommandHooks extends React.Component {
+export default class ManageCommandCmds extends React.Component {
     constructor() {
         super();
 
-        this.getHooks = this.getHooks.bind(this);
-        this.addNewHook = this.addNewHook.bind(this);
+        this.getCmds = this.getCmds.bind(this);
+        this.addNewCmd = this.addNewCmd.bind(this);
+        this.emptyCmd = this.emptyCmd.bind(this);
         this.updateTrigger = this.updateTrigger.bind(this);
         this.updateURL = this.updateURL.bind(this);
+        this.updateMethod = this.updateMethod.bind(this);
+        this.updateUsername = this.updateUsername.bind(this);
+        this.updateIconURL = this.updateIconURL.bind(this);
+        this.updateDisplayName = this.updateDisplayName.bind(this);
+        this.updateAutoComplete = this.updateAutoComplete.bind(this);
+        this.updateAutoCompleteDesc = this.updateAutoCompleteDesc.bind(this);
+        this.updateAutoCompleteHint = this.updateAutoCompleteHint.bind(this);
 
-        this.state = {hooks: [], channelId: '', trigger: '', URL: '', getHooksComplete: false};
+        this.state = {cmds: [], cmd: this.emptyCmd(), getCmdsComplete: false};
+    }
+
+    emptyCmd() {
+        var cmd = {};
+        cmd.url = '';
+        cmd.trigger = '';
+        cmd.method = 'P';
+        cmd.username = '';
+        cmd.icon_url = '';
+        cmd.auto_complete = false;
+        cmd.auto_complete_desc = '';
+        cmd.auto_complete_hint = '';
+        cmd.display_name = '';
+        return cmd;
     }
 
     componentDidMount() {
-        this.getHooks();
+        this.getCmds();
     }
 
-    addNewHook(e) {
+    addNewCmd(e) {
         e.preventDefault();
 
-        if (this.state.trigger === '' || this.state.URL === '') {
+        if (this.state.cmd.trigger === '' || this.state.cmd.url === '') {
             return;
         }
 
-        const hook = {};
-        if (this.state.trigger.length !== 0) {
-            hook.trigger = this.state.trigger.trim();
+        var cmd = this.state.cmd;
+        if (cmd.trigger.length !== 0) {
+            cmd.trigger = cmd.trigger.trim();
         }
-        hook.url = this.state.URL.trim();
+        cmd.url = cmd.url.trim();
 
         Client.addCommand(
-            hook,
+            cmd,
             (data) => {
-                let hooks = Object.assign([], this.state.hooks);
-                if (!hooks) {
-                    hooks = [];
+                let cmds = Object.assign([], this.state.cmds);
+                if (!cmds) {
+                    cmds = [];
                 }
-                hooks.push(data);
-                this.setState({hooks, addError: null, triggerWords: '', URL: ''});
+                cmds.push(data);
+                this.setState({cmds, addError: null, cmd: this.emptyCmd()});
             },
             (err) => {
                 this.setState({addError: err.message});
@@ -50,27 +72,27 @@ export default class ManageCommandHooks extends React.Component {
         );
     }
 
-    removeHook(id) {
+    removeCmd(id) {
         const data = {};
         data.id = id;
 
         Client.deleteCommand(
             data,
             () => {
-                const hooks = this.state.hooks;
+                const cmds = this.state.cmds;
                 let index = -1;
-                for (let i = 0; i < hooks.length; i++) {
-                    if (hooks[i].id === id) {
+                for (let i = 0; i < cmds.length; i++) {
+                    if (cmds[i].id === id) {
                         index = i;
                         break;
                     }
                 }
 
                 if (index !== -1) {
-                    hooks.splice(index, 1);
+                    cmds.splice(index, 1);
                 }
 
-                this.setState({hooks});
+                this.setState({cmds});
             },
             (err) => {
                 this.setState({editError: err.message});
@@ -85,15 +107,15 @@ export default class ManageCommandHooks extends React.Component {
         Client.regenCommandToken(
             regenData,
             (data) => {
-                const hooks = Object.assign([], this.state.hooks);
-                for (let i = 0; i < hooks.length; i++) {
-                    if (hooks[i].id === id) {
-                        hooks[i] = data;
+                const cmds = Object.assign([], this.state.cmds);
+                for (let i = 0; i < cmds.length; i++) {
+                    if (cmds[i].id === id) {
+                        cmds[i] = data;
                         break;
                     }
                 }
 
-                this.setState({hooks, editError: null});
+                this.setState({cmds, editError: null});
             },
             (err) => {
                 this.setState({editError: err.message});
@@ -101,11 +123,11 @@ export default class ManageCommandHooks extends React.Component {
         );
     }
 
-    getHooks() {
-        Client.listCommands(
+    getCmds() {
+        Client.listTeamCommands(
             (data) => {
                 if (data) {
-                    this.setState({hooks: data, getHooksComplete: true, editError: null});
+                    this.setState({cmds: data, getCmdsComplete: true, editError: null});
                 }
             },
             (err) => {
@@ -115,11 +137,57 @@ export default class ManageCommandHooks extends React.Component {
     }
 
     updateTrigger(e) {
-        this.setState({trigger: e.target.value});
+        var cmd = this.state.cmd;
+        cmd.trigger = e.target.value;
+        this.setState(cmd);
     }
 
     updateURL(e) {
-        this.setState({URL: e.target.value});
+        var cmd = this.state.cmd;
+        cmd.url = e.target.value;
+        this.setState(cmd);
+    }
+
+    updateMethod(e) {
+        var cmd = this.state.cmd;
+        cmd.method = e.target.value;
+        this.setState(cmd);
+    }
+
+    updateUsername(e) {
+        var cmd = this.state.cmd;
+        cmd.username = e.target.value;
+        this.setState(cmd);
+    }
+
+    updateIconURL(e) {
+        var cmd = this.state.cmd;
+        cmd.icon_url = e.target.value;
+        this.setState(cmd);
+    }
+
+    updateDisplayName(e) {
+        var cmd = this.state.cmd;
+        cmd.display_name = e.target.value;
+        this.setState(cmd);
+    }
+
+    updateAutoComplete(e) {
+        var cmd = this.state.cmd;
+        cmd.auto_complete = e.target.checked;
+        this.setState(cmd);
+    }
+
+    updateAutoCompleteDesc(e) {
+        var cmd = this.state.cmd;
+        cmd.auto_complete_desc = e.target.value;
+        this.setState(cmd);
+    }
+
+    updateAutoCompleteHint(e) {
+        var cmd = this.state.cmd;
+        cmd.auto_complete_hint = e.target.value;
+        this.setState(cmd);
     }
 
     render() {
@@ -133,41 +201,62 @@ export default class ManageCommandHooks extends React.Component {
             addError = <label className='has-error'>{this.state.editError}</label>;
         }
 
-        const hooks = [];
-        this.state.hooks.forEach((hook) => {
+        const cmds = [];
+        this.state.cmds.forEach((cmd) => {
             let triggerDiv;
-            if (hook.trigger && hook.trigger.length !== 0) {
+            if (cmd.trigger && cmd.trigger.length !== 0) {
                 triggerDiv = (
                     <div className='padding-top'>
-                        <strong>{'Trigger: '}</strong>{hook.trigger}
+                        <strong>{'Trigger: '}</strong>{cmd.trigger}
                     </div>
                 );
             }
 
-            hooks.push(
+            cmds.push(
                 <div
-                    key={hook.id}
-                    className='webhook__item'
+                    key={cmd.id}
+                    className='webcmd__item'
                 >
-                    <div className='padding-top x2 webhook__url'>
-                        <strong>{'URL: '}</strong><span className='word-break--all'>{hook.url}</span>
+                    <div className='padding-top x2'>
+                        <strong>{'Display Name: '}</strong><span className='word-break--all'>{cmd.display_name}</span>
+                    </div>
+                    <div className='padding-top x2'>
+                        <strong>{'Username: '}</strong><span className='word-break--all'>{cmd.username}</span>
+                    </div>
+                    <div className='padding-top x2'>
+                        <strong>{'Icon URL: '}</strong><span className='word-break--all'>{cmd.icon_url}</span>
+                    </div>
+                    <div className='padding-top x2'>
+                        <strong>{'Auto Complete: '}</strong><span className='word-break--all'>{cmd.auto_complete ? 'yes' : 'no'}</span>
+                    </div>
+                    <div className='padding-top x2'>
+                        <strong>{'Auto Complete Description: '}</strong><span className='word-break--all'>{cmd.auto_complete_desc}</span>
+                    </div>
+                    <div className='padding-top x2'>
+                        <strong>{'Auto Complete Hint: '}</strong><span className='word-break--all'>{cmd.auto_complete_hint}</span>
+                    </div>
+                    <div className='padding-top x2'>
+                        <strong>{'Request Type: '}</strong><span className='word-break--all'>{cmd.method === 'P' ? 'POST' : 'GET'}</span>
+                    </div>
+                    <div className='padding-top x2 webcmd__url'>
+                        <strong>{'URL: '}</strong><span className='word-break--all'>{cmd.url}</span>
                     </div>
                     {triggerDiv}
                     <div className='padding-top'>
-                        <strong>{'Token: '}</strong>{hook.token}
+                        <strong>{'Token: '}</strong>{cmd.token}
                     </div>
                     <div className='padding-top'>
                         <a
                             className='text-danger'
                             href='#'
-                            onClick={this.regenToken.bind(this, hook.id)}
+                            onClick={this.regenToken.bind(this, cmd.id)}
                         >
                             {'Regen Token'}
                         </a>
                         <a
-                            className='webhook__remove'
+                            className='webcmd__remove'
                             href='#'
-                            onClick={this.removeHook.bind(this, hook.id)}
+                            onClick={this.removeCmd.bind(this, cmd.id)}
                         >
                             <span aria-hidden='true'>{'×'}</span>
                         </a>
@@ -177,29 +266,29 @@ export default class ManageCommandHooks extends React.Component {
             );
         });
 
-        let displayHooks;
-        if (!this.state.getHooksComplete) {
-            displayHooks = <LoadingScreen/>;
-        } else if (hooks.length > 0) {
-            displayHooks = hooks;
+        let displayCmds;
+        if (!this.state.getCmdsComplete) {
+            displayCmds = <LoadingScreen/>;
+        } else if (cmds.length > 0) {
+            displayCmds = cmds;
         } else {
-            displayHooks = <div className='padding-top x2'>{'None'}</div>;
+            displayCmds = <div className='padding-top x2'>{'None'}</div>;
         }
 
-        const existingHooks = (
-            <div className='webhooks__container'>
+        const existingCmds = (
+            <div className='webcmds__container'>
                 <label className='control-label padding-top x2'>{'Existing commands'}</label>
                 <div className='padding-top divider-light'></div>
-                <div className='webhooks__list'>
-                    {displayHooks}
+                <div className='webcmds__list'>
+                    {displayCmds}
                 </div>
             </div>
         );
 
-        const disableButton = this.state.trigger === '' || this.state.URL === '';
+        const disableButton = this.state.cmd.trigger === '' || this.state.cmd.url === '';
 
         return (
-            <div key='addCommandHook'>
+            <div key='addCommandCmd'>
                 {'Create commands to send new message events to an external integration. Please see '}
                 <a
                     href='http://mattermost.org/commands'
@@ -211,6 +300,45 @@ export default class ManageCommandHooks extends React.Component {
                 <div><label className='control-label padding-top x2'>{'Add a new command'}</label></div>
                 <div className='padding-top divider-light'></div>
                 <div className='padding-top'>
+                    <div className='padding-top x2'>
+                        <label className='control-label'>{'Display Name:'}</label>
+                        <div className='padding-top'>
+                            <input
+                                ref='displayName'
+                                className='form-control'
+                                value={this.state.cmd.display_name}
+                                onChange={this.updateDisplayName}
+                                placeholder='Display Name'
+                            />
+                        </div>
+                        <div className='padding-top'>{'Command display name.'}</div>
+                    </div>
+                    <div className='padding-top x2'>
+                        <label className='control-label'>{'Username:'}</label>
+                        <div className='padding-top'>
+                            <input
+                                ref='username'
+                                className='form-control'
+                                value={this.state.cmd.username}
+                                onChange={this.updateUsername}
+                                placeholder='Username'
+                            />
+                        </div>
+                        <div className='padding-top'>{'The username to use when overriding the post.'}</div>
+                    </div>
+                    <div className='padding-top x2'>
+                        <label className='control-label'>{'Icon URL:'}</label>
+                        <div className='padding-top'>
+                            <input
+                                ref='iconURL'
+                                className='form-control'
+                                value={this.state.cmd.icon_url}
+                                onChange={this.updateIconURL}
+                                placeholder='https://www.example.com/myicon.png'
+                            />
+                        </div>
+                        <div className='padding-top'>{'URL to an icon'}</div>
+                    </div>
                     <div className='padding-top x2'>
                         <label className='control-label'>{'Trigger:'}</label>
                         <div className='padding-top'>
@@ -218,23 +346,77 @@ export default class ManageCommandHooks extends React.Component {
                             <input
                                 ref='trigger'
                                 className='form-control'
-                                value={this.state.trigger}
+                                value={this.state.cmd.trigger}
                                 onChange={this.updateTrigger}
                                 placeholder='Command trigger e.g. "hello" not including the slash'
                             />
                         </div>
                         <div className='padding-top'>{'Word to trigger on'}</div>
                     </div>
+                    <div className='padding-top x2'>
+                        <label className='control-label'>{'Autocomplete:'}</label>
+                        <div className='padding-top'>
+                            <label>
+                                <input
+                                    type='checkbox'
+                                    checked={this.state.cmd.auto_complete}
+                                    onChange={this.updateAutoComplete}
+                                />
+                                {'A short description of what this commands does'}
+                            </label>
+                        </div>
+                        <div className='padding-top'>{'Show this command in autocomplete list.'}</div>
+                    </div>
+                    <div className='padding-top x2'>
+                        <label className='control-label'>{'Autocomplete Description:'}</label>
+                        <div className='padding-top'>
+                            <input
+                                ref='autoCompleteDesc'
+                                className='form-control'
+                                value={this.state.cmd.auto_complete_desc}
+                                onChange={this.updateAutoCompleteDesc}
+                                placeholder='A short description of what this commands does.'
+                            />
+                        </div>
+                        <div className='padding-top'>{'A short description of what this commands does.'}</div>
+                    </div>
+                    <div className='padding-top x2'>
+                        <label className='control-label'>{'Autocomplete Hint:'}</label>
+                        <div className='padding-top'>
+                            <input
+                                ref='autoCompleteHint'
+                                className='form-control'
+                                value={this.state.cmd.auto_complete_hint}
+                                onChange={this.updateAutoCompleteHint}
+                                placeholder='[zipcode]'
+                            />
+                        </div>
+                        <div className='padding-top'>{'List parameters to be passed to the command.'}</div>
+                    </div>
+                    <div className='padding-top x2'>
+                        <label className='control-label'>{'Request Type:'}</label>
+                        <div className='padding-top'>
+                            <select
+                                ref='method'
+                                className='form-control'
+                                value={this.state.cmd.method}
+                                onChange={this.updateMethod}
+                            >
+                                <option value='P'>{'POST'}</option>
+                                <option value='G'>{'GET'}</option>
+                            </select>
+                        </div>
+                        <div className='padding-top'>{'Command request type issued to the callback URL.'}</div>
+                    </div>
                     <div className='padding-top x2'>
                         <label className='control-label'>{'Callback URL:'}</label>
                         <div className='padding-top'>
-                        <textarea
+                        <input
                             ref='URL'
-                            className='form-control no-resize'
-                            value={this.state.URL}
-                            resize={false}
-                            rows={3}
-                            onChange={this.URL}
+                            className='form-control'
+                            value={this.state.cmd.url}
+                            rows={1}
+                            onChange={this.updateURL}
                             placeholder='Must start with http:// or https://'
                         />
                         </div>
@@ -246,13 +428,13 @@ export default class ManageCommandHooks extends React.Component {
                             className={'btn btn-sm btn-primary'}
                             href='#'
                             disabled={disableButton}
-                            onClick={this.addNewHook}
+                            onClick={this.addNewCmd}
                         >
                             {'Add'}
                         </a>
                     </div>
                 </div>
-                {existingHooks}
+                {existingCmds}
                 {editError}
             </div>
         );
-- 
cgit v1.2.3-1-g7c22


From ff54da2e4a1095a6f96f285aa218a5d162b68b51 Mon Sep 17 00:00:00 2001
From: =Corey Hulen <corey@hulen.com>
Date: Tue, 2 Feb 2016 08:42:36 -0800
Subject: Adding loc to front-end

---
 .../user_settings/manage_command_hooks.jsx         | 306 +++++++++++++++++----
 1 file changed, 258 insertions(+), 48 deletions(-)

(limited to 'web/react/components/user_settings/manage_command_hooks.jsx')

diff --git a/web/react/components/user_settings/manage_command_hooks.jsx b/web/react/components/user_settings/manage_command_hooks.jsx
index 1fb3bf599..bcf0a6c82 100644
--- a/web/react/components/user_settings/manage_command_hooks.jsx
+++ b/web/react/components/user_settings/manage_command_hooks.jsx
@@ -5,6 +5,43 @@ import LoadingScreen from '../loading_screen.jsx';
 
 import * as Client from '../../utils/client.jsx';
 
+import {intlShape, injectIntl, defineMessages, FormattedMessage, FormattedHTMLMessage} from 'mm-intl';
+
+const holders = defineMessages({
+    requestTypePost: {
+        id: 'user.settings.cmds.request_type_post',
+        defaultMessage: 'POST'
+    },
+    requestTypeGet: {
+        id: 'user.settings.cmds.request_type_get',
+        defaultMessage: 'GET'
+    },
+    addDisplayNamePlaceholder: {
+        id: 'user.settings.cmds.add_display_name.placeholder',
+        defaultMessage: 'Display Name'
+    },
+    addUsernamePlaceholder: {
+        id: 'user.settings.cmds.add_username.placeholder',
+        defaultMessage: 'Username'
+    },
+    addTriggerPlaceholder: {
+        id: 'user.settings.cmds.add_trigger.placeholder',
+        defaultMessage: 'Command trigger e.g. "hello" not including the slash'
+    },
+    addAutoCompleteDescPlaceholder: {
+        id: 'user.settings.cmds.auto_complete_desc.placeholder',
+        defaultMessage: 'A short description of what this commands does.'
+    },
+    addAutoCompleteHintPlaceholder: {
+        id: 'user.settings.cmds.auto_complete_hint.placeholder',
+        defaultMessage: '[zipcode]'
+    },
+    adUrlPlaceholder: {
+        id: 'user.settings.cmds.url.placeholder',
+        defaultMessage: 'Must start with http:// or https://'
+    }
+});
+
 export default class ManageCommandCmds extends React.Component {
     constructor() {
         super();
@@ -25,6 +62,12 @@ export default class ManageCommandCmds extends React.Component {
         this.state = {cmds: [], cmd: this.emptyCmd(), getCmdsComplete: false};
     }
 
+    static propTypes() {
+        return {
+            intl: intlShape.isRequired
+        };
+    }
+
     emptyCmd() {
         var cmd = {};
         cmd.url = '';
@@ -207,7 +250,12 @@ export default class ManageCommandCmds extends React.Component {
             if (cmd.trigger && cmd.trigger.length !== 0) {
                 triggerDiv = (
                     <div className='padding-top'>
-                        <strong>{'Trigger: '}</strong>{cmd.trigger}
+                        <strong>
+                            <FormattedMessage
+                                id='user.settings.cmds.trigger'
+                                defaultMessage='Trigger: '
+                            />
+                        </strong>{cmd.trigger}
                     </div>
                 );
             }
@@ -218,32 +266,90 @@ export default class ManageCommandCmds extends React.Component {
                     className='webcmd__item'
                 >
                     <div className='padding-top x2'>
-                        <strong>{'Display Name: '}</strong><span className='word-break--all'>{cmd.display_name}</span>
+                        <strong>
+                            <FormattedMessage
+                                id='user.settings.cmds.display_name'
+                                defaultMessage='Display Name: '
+                            />
+                        </strong><span className='word-break--all'>{cmd.display_name}</span>
                     </div>
                     <div className='padding-top x2'>
-                        <strong>{'Username: '}</strong><span className='word-break--all'>{cmd.username}</span>
+                        <strong>
+                            <FormattedMessage
+                                id='user.settings.cmds.username'
+                                defaultMessage='Username: '
+                            />
+                        </strong><span className='word-break--all'>{cmd.username}</span>
                     </div>
                     <div className='padding-top x2'>
-                        <strong>{'Icon URL: '}</strong><span className='word-break--all'>{cmd.icon_url}</span>
+                        <strong>
+                            <FormattedMessage
+                                id='user.settings.cmds.icon_url'
+                                defaultMessage='Icon URL: '
+                            />
+                        </strong><span className='word-break--all'>{cmd.icon_url}</span>
                     </div>
                     <div className='padding-top x2'>
-                        <strong>{'Auto Complete: '}</strong><span className='word-break--all'>{cmd.auto_complete ? 'yes' : 'no'}</span>
+                        <strong>
+                            <FormattedMessage
+                                id='user.settings.cmds.auto_complete'
+                                defaultMessage='Auto Complete: '
+                            />
+                        </strong><span className='word-break--all'>{cmd.auto_complete ? 'yes' : 'no'}</span>
                     </div>
                     <div className='padding-top x2'>
-                        <strong>{'Auto Complete Description: '}</strong><span className='word-break--all'>{cmd.auto_complete_desc}</span>
+                        <strong>
+                            <FormattedMessage
+                                id='user.settings.cmds.auto_complete_desc'
+                                defaultMessage='Auto Complete Description: '
+                            />
+                        </strong><span className='word-break--all'>{cmd.auto_complete_desc}</span>
                     </div>
                     <div className='padding-top x2'>
-                        <strong>{'Auto Complete Hint: '}</strong><span className='word-break--all'>{cmd.auto_complete_hint}</span>
+                        <strong>
+                            <FormattedMessage
+                                id='user.settings.cmds.auto_complete_hint'
+                                defaultMessage='Auto Complete Hint: '
+                            />
+                        </strong><span className='word-break--all'>{cmd.auto_complete_hint}</span>
                     </div>
                     <div className='padding-top x2'>
-                        <strong>{'Request Type: '}</strong><span className='word-break--all'>{cmd.method === 'P' ? 'POST' : 'GET'}</span>
+                        <strong>
+                            <FormattedMessage
+                                id='user.settings.cmds.request_type'
+                                defaultMessage='Request Type: '
+                            />
+                        </strong>
+                        <span className='word-break--all'>
+                            {
+                                cmd.method === 'P' ?
+                                <FormattedMessage
+                                    id='user.settings.cmds.request_type_post'
+                                    defaultMessage='POST'
+                                /> :
+                                <FormattedMessage
+                                    id='user.settings.cmds.request_type_get'
+                                    defaultMessage='GET'
+                                />
+                            }
+                        </span>
                     </div>
                     <div className='padding-top x2 webcmd__url'>
-                        <strong>{'URL: '}</strong><span className='word-break--all'>{cmd.url}</span>
+                        <strong>
+                            <FormattedMessage
+                                id='user.settings.cmds.url'
+                                defaultMessage='URL: '
+                            />
+                        </strong><span className='word-break--all'>{cmd.url}</span>
                     </div>
                     {triggerDiv}
                     <div className='padding-top'>
-                        <strong>{'Token: '}</strong>{cmd.token}
+                        <strong>
+                            <FormattedMessage
+                                id='user.settings.cmds.token'
+                                defaultMessage='Token: '
+                            />
+                        </strong>{cmd.token}
                     </div>
                     <div className='padding-top'>
                         <a
@@ -251,7 +357,10 @@ export default class ManageCommandCmds extends React.Component {
                             href='#'
                             onClick={this.regenToken.bind(this, cmd.id)}
                         >
-                            {'Regen Token'}
+                            <FormattedMessage
+                                id='user.settings.cmds.regen'
+                                defaultMessage='Regen Token'
+                            />
                         </a>
                         <a
                             className='webcmd__remove'
@@ -272,12 +381,24 @@ export default class ManageCommandCmds extends React.Component {
         } else if (cmds.length > 0) {
             displayCmds = cmds;
         } else {
-            displayCmds = <div className='padding-top x2'>{'None'}</div>;
+            displayCmds = (
+                <div className='padding-top x2'>
+                    <FormattedMessage
+                        id='user.settings.cmds.none'
+                        defaultMessage='None'
+                    />
+                </div>
+            );
         }
 
         const existingCmds = (
             <div className='webcmds__container'>
-                <label className='control-label padding-top x2'>{'Existing commands'}</label>
+                <label className='control-label padding-top x2'>
+                    <FormattedMessage
+                        id='user.settings.cmds.existing'
+                        defaultMessage='Existing commands'
+                    />
+                </label>
                 <div className='padding-top divider-light'></div>
                 <div className='webcmds__list'>
                     {displayCmds}
@@ -289,45 +410,61 @@ export default class ManageCommandCmds extends React.Component {
 
         return (
             <div key='addCommandCmd'>
-                {'Create commands to send new message events to an external integration. Please see '}
-                <a
-                    href='http://mattermost.org/commands'
-                    target='_blank'
-                >
-                    {'http://mattermost.org/commands'}
-                </a>
-                {' to learn more.'}
+                <FormattedHTMLMessage
+                    id='user.settings.cmds.add_desc'
+                    defaultMessage='Create commands to send message events to an external integration. Please see <a href="http://mattermost.org/commands">http://mattermost.org/commands</a>  to learn more.'
+                />
                 <div><label className='control-label padding-top x2'>{'Add a new command'}</label></div>
                 <div className='padding-top divider-light'></div>
                 <div className='padding-top'>
                     <div className='padding-top x2'>
-                        <label className='control-label'>{'Display Name:'}</label>
+                        <label className='control-label'>
+                            <FormattedMessage
+                                id='user.settings.cmds.display_name'
+                                defaultMessage='Display Name: '
+                            />
+                        </label>
                         <div className='padding-top'>
                             <input
                                 ref='displayName'
                                 className='form-control'
                                 value={this.state.cmd.display_name}
                                 onChange={this.updateDisplayName}
-                                placeholder='Display Name'
+                                placeholder={this.props.intl.formatMessage(holders.addDisplayNamePlaceholder)}
                             />
                         </div>
                         <div className='padding-top'>{'Command display name.'}</div>
                     </div>
                     <div className='padding-top x2'>
-                        <label className='control-label'>{'Username:'}</label>
+                        <label className='control-label'>
+                            <FormattedMessage
+                                id='user.settings.cmds.username'
+                                defaultMessage='Username: '
+                            />
+                        </label>
                         <div className='padding-top'>
                             <input
                                 ref='username'
                                 className='form-control'
                                 value={this.state.cmd.username}
                                 onChange={this.updateUsername}
-                                placeholder='Username'
+                                placeholder={this.props.intl.formatMessage(holders.addUsernamePlaceholder)}
+                            />
+                        </div>
+                        <div className='padding-top'>
+                            <FormattedMessage
+                                id='user.settings.cmds.username_desc'
+                                defaultMessage='The username to use when overriding the post.'
                             />
                         </div>
-                        <div className='padding-top'>{'The username to use when overriding the post.'}</div>
                     </div>
                     <div className='padding-top x2'>
-                        <label className='control-label'>{'Icon URL:'}</label>
+                        <label className='control-label'>
+                            <FormattedMessage
+                                id='user.settings.cmds.icon_url'
+                                defaultMessage='Icon URL: '
+                            />
+                        </label>
                         <div className='padding-top'>
                             <input
                                 ref='iconURL'
@@ -337,24 +474,43 @@ export default class ManageCommandCmds extends React.Component {
                                 placeholder='https://www.example.com/myicon.png'
                             />
                         </div>
-                        <div className='padding-top'>{'URL to an icon'}</div>
+                        <div className='padding-top'>
+                            <FormattedMessage
+                                id='user.settings.cmds.icon_url_desc'
+                                defaultMessage='URL to an icon'
+                            />
+                        </div>
                     </div>
                     <div className='padding-top x2'>
-                        <label className='control-label'>{'Trigger:'}</label>
+                        <label className='control-label'>
+                            <FormattedMessage
+                                id='user.settings.cmds.trigger'
+                                defaultMessage='Trigger: '
+                            />
+                        </label>
                         <div className='padding-top'>
-                            {'/'}
                             <input
                                 ref='trigger'
                                 className='form-control'
                                 value={this.state.cmd.trigger}
                                 onChange={this.updateTrigger}
-                                placeholder='Command trigger e.g. "hello" not including the slash'
+                                placeholder={this.props.intl.formatMessage(holders.addTriggerPlaceholder)}
                             />
                         </div>
-                        <div className='padding-top'>{'Word to trigger on'}</div>
+                        <div className='padding-top'>
+                            <FormattedMessage
+                                id='user.settings.cmds.trigger_desc'
+                                defaultMessage='Word to trigger on'
+                            />
+                        {''}</div>
                     </div>
                     <div className='padding-top x2'>
-                        <label className='control-label'>{'Autocomplete:'}</label>
+                        <label className='control-label'>
+                            <FormattedMessage
+                                id='user.settings.cmds.auto_complete'
+                                defaultMessage='Auto Complete: '
+                            />
+                        </label>
                         <div className='padding-top'>
                             <label>
                                 <input
@@ -362,39 +518,72 @@ export default class ManageCommandCmds extends React.Component {
                                     checked={this.state.cmd.auto_complete}
                                     onChange={this.updateAutoComplete}
                                 />
-                                {'A short description of what this commands does'}
+                                <FormattedMessage
+                                    id='user.settings.cmds.auto_complete_desc_desc'
+                                    defaultMessage='A short description of what this commands does'
+                                />
                             </label>
                         </div>
-                        <div className='padding-top'>{'Show this command in autocomplete list.'}</div>
+                        <div className='padding-top'>
+                            <FormattedMessage
+                                id='user.settings.cmds.auto_complete_help'
+                                defaultMessage='Show this command in autocomplete list.'
+                            />
+                        </div>
                     </div>
                     <div className='padding-top x2'>
-                        <label className='control-label'>{'Autocomplete Description:'}</label>
+                        <label className='control-label'>
+                            <FormattedMessage
+                                id='user.settings.cmds.auto_complete_desc'
+                                defaultMessage='Auto Complete Description: '
+                            />
+                        </label>
                         <div className='padding-top'>
                             <input
                                 ref='autoCompleteDesc'
                                 className='form-control'
                                 value={this.state.cmd.auto_complete_desc}
                                 onChange={this.updateAutoCompleteDesc}
-                                placeholder='A short description of what this commands does.'
+                                placeholder={this.props.intl.formatMessage(holders.addAutoCompleteDescPlaceholder)}
+                            />
+                        </div>
+                        <div className='padding-top'>
+                            <FormattedMessage
+                                id='user.settings.cmds.auto_complete_desc_desc'
+                                defaultMessage='A short description of what this commands does'
                             />
                         </div>
-                        <div className='padding-top'>{'A short description of what this commands does.'}</div>
                     </div>
                     <div className='padding-top x2'>
-                        <label className='control-label'>{'Autocomplete Hint:'}</label>
+                        <label className='control-label'>
+                            <FormattedMessage
+                                id='user.settings.cmds.auto_complete_hint'
+                                defaultMessage='Auto Complete Hint: '
+                            />
+                        </label>
                         <div className='padding-top'>
                             <input
                                 ref='autoCompleteHint'
                                 className='form-control'
                                 value={this.state.cmd.auto_complete_hint}
                                 onChange={this.updateAutoCompleteHint}
-                                placeholder='[zipcode]'
+                                placeholder={this.props.intl.formatMessage(holders.addAutoCompleteHintPlaceholder)}
+                            />
+                        </div>
+                        <div className='padding-top'>
+                            <FormattedMessage
+                                id='user.settings.cmds.auto_complete_hint_desc'
+                                defaultMessage='List parameters to be passed to the command.'
                             />
                         </div>
-                        <div className='padding-top'>{'List parameters to be passed to the command.'}</div>
                     </div>
                     <div className='padding-top x2'>
-                        <label className='control-label'>{'Request Type:'}</label>
+                        <label className='control-label'>
+                            <FormattedMessage
+                                id='user.settings.cmds.request_type'
+                                defaultMessage='Request Type: '
+                            />
+                        </label>
                         <div className='padding-top'>
                             <select
                                 ref='method'
@@ -402,14 +591,28 @@ export default class ManageCommandCmds extends React.Component {
                                 value={this.state.cmd.method}
                                 onChange={this.updateMethod}
                             >
-                                <option value='P'>{'POST'}</option>
-                                <option value='G'>{'GET'}</option>
+                                <option value='P'>
+                                    {this.props.intl.formatMessage(holders.requestTypePost)}
+                                </option>
+                                <option value='G'>
+                                    {this.props.intl.formatMessage(holders.requestTypeGet)}
+                                </option>
                             </select>
                         </div>
-                        <div className='padding-top'>{'Command request type issued to the callback URL.'}</div>
+                        <div className='padding-top'>
+                            <FormattedMessage
+                                id='user.settings.cmds.request_type_desc'
+                                defaultMessage='Command request type issued to the callback URL.'
+                            />
+                        </div>
                     </div>
                     <div className='padding-top x2'>
-                        <label className='control-label'>{'Callback URL:'}</label>
+                        <label className='control-label'>
+                            <FormattedMessage
+                                id='user.settings.cmds.url'
+                                defaultMessage='URL: '
+                            />
+                        </label>
                         <div className='padding-top'>
                         <input
                             ref='URL'
@@ -417,10 +620,15 @@ export default class ManageCommandCmds extends React.Component {
                             value={this.state.cmd.url}
                             rows={1}
                             onChange={this.updateURL}
-                            placeholder='Must start with http:// or https://'
+                            placeholder={this.props.intl.formatMessage(holders.adUrlPlaceholder)}
                         />
                         </div>
-                        <div className='padding-top'>{'URL that will receive the HTTP POST or GET event'}</div>
+                        <div className='padding-top'>
+                            <FormattedMessage
+                                id='user.settings.cmds.url_desc'
+                                defaultMessage='URL that will receive the HTTP POST or GET event'
+                            />
+                        </div>
                         {addError}
                     </div>
                     <div className='padding-top padding-bottom'>
@@ -440,3 +648,5 @@ export default class ManageCommandCmds extends React.Component {
         );
     }
 }
+
+export default injectIntl(ManageCommandCmds);
-- 
cgit v1.2.3-1-g7c22

