From 3fba8e42b140c1189bf3c06882cce5e2231e63da Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Fri, 8 Jan 2016 12:41:26 -0600 Subject: partial fix for UI --- web/react/utils/async_client.jsx | 20 ++++++++++++++------ web/react/utils/client.jsx | 16 +++++++++++++++- 2 files changed, 29 insertions(+), 7 deletions(-) (limited to 'web/react/utils') diff --git a/web/react/utils/async_client.jsx b/web/react/utils/async_client.jsx index f218270da..78be646ac 100644 --- a/web/react/utils/async_client.jsx +++ b/web/react/utils/async_client.jsx @@ -747,20 +747,28 @@ export function savePreferences(preferences, success, error) { } export function getSuggestedCommands(command, suggestionId, component) { - client.executeCommand( - '', - command, - true, + client.listCommands( (data) => { + var matches = []; + data.forEach((cmd) => { + if (('/' + cmd.trigger).indexOf(command) === 0) { + matches.push({ + suggestion: '/' + cmd.trigger + ' ' + cmd.auto_complete_hint, + description: cmd.auto_complete_desc + }); + } + }); + // pull out the suggested commands from the returned data - const terms = data.suggestions.map((suggestion) => suggestion.suggestion); + //const terms = matches.map((suggestion) => suggestion.trigger); + const terms = matches.map((suggestion) => suggestion.suggestion); AppDispatcher.handleServerAction({ type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS, id: suggestionId, matchedPretext: command, terms, - items: data.suggestions, + items: matches, component }); }, diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx index e1c331aff..56c8c4b3e 100644 --- a/web/react/utils/client.jsx +++ b/web/react/utils/client.jsx @@ -839,7 +839,7 @@ export function getChannelExtraInfo(id, success, error) { export function executeCommand(channelId, command, suggest, success, error) { $.ajax({ - url: '/api/v1/command', + url: '/api/v1/commands/execute', dataType: 'json', contentType: 'application/json', type: 'POST', @@ -852,6 +852,20 @@ export function executeCommand(channelId, command, suggest, success, error) { }); } +export function listCommands(success, error) { + $.ajax({ + url: '/api/v1/commands/list', + dataType: 'json', + contentType: 'application/json', + type: 'POST', + success, + error: function onError(xhr, status, err) { + var e = handleError('listCommands', xhr, status, err); + error(e); + } + }); +} + export function getPostsPage(channelId, offset, limit, success, error, complete) { $.ajax({ cache: false, -- cgit v1.2.3-1-g7c22 From 3edcf960a0502fbeb3e4b46e87ecb958646eeb39 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Sat, 9 Jan 2016 09:22:14 -0600 Subject: Fixing unit tests --- web/react/utils/client.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/react/utils') diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx index 56c8c4b3e..39629b529 100644 --- a/web/react/utils/client.jsx +++ b/web/react/utils/client.jsx @@ -857,7 +857,7 @@ export function listCommands(success, error) { url: '/api/v1/commands/list', dataType: 'json', contentType: 'application/json', - type: 'POST', + type: 'GET', success, error: function onError(xhr, status, err) { var e = handleError('listCommands', xhr, status, err); -- cgit v1.2.3-1-g7c22 From 586967b757a869dbb5f3677e605009a1f5c61005 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Thu, 14 Jan 2016 10:52:14 -0600 Subject: finishing up commands UI --- web/react/utils/client.jsx | 60 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'web/react/utils') diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx index 9ff76f824..07982b7be 100644 --- a/web/react/utils/client.jsx +++ b/web/react/utils/client.jsx @@ -850,7 +850,7 @@ export function executeCommand(channelId, command, suggest, success, error) { dataType: 'json', contentType: 'application/json', type: 'POST', - data: JSON.stringify({channelId: channelId, command: command, suggest: '' + suggest}), + data: JSON.stringify({channelId, command, suggest: '' + suggest}), success, error: function onError(xhr, status, err) { var e = handleError('executeCommand', xhr, status, err); @@ -859,6 +859,64 @@ export function executeCommand(channelId, command, suggest, success, error) { }); } +export function addCommand(cmd, success, error) { + $.ajax({ + url: '/api/v1/commands/create', + dataType: 'json', + contentType: 'application/json', + type: 'POST', + data: JSON.stringify(cmd), + success, + error: (xhr, status, err) => { + var e = handleError('addCommand', xhr, status, err); + error(e); + } + }); +} + +export function deleteCommand(data, success, error) { + $.ajax({ + url: '/api/v1/commands/delete', + dataType: 'json', + contentType: 'application/json', + type: 'POST', + data: JSON.stringify(data), + success, + error: (xhr, status, err) => { + var e = handleError('deleteCommand', xhr, status, err); + error(e); + } + }); +} + +export function listTeamCommands(success, error) { + $.ajax({ + url: '/api/v1/commands/list_team_commands', + dataType: 'json', + type: 'GET', + success, + error: (xhr, status, err) => { + var e = handleError('listTeamCommands', xhr, status, err); + error(e); + } + }); +} + +export function regenCommandToken(data, success, error) { + $.ajax({ + url: '/api/v1/commands/regen_token', + dataType: 'json', + contentType: 'application/json', + type: 'POST', + data: JSON.stringify(data), + success, + error: (xhr, status, err) => { + var e = handleError('regenCommandToken', xhr, status, err); + error(e); + } + }); +} + export function listCommands(success, error) { $.ajax({ url: '/api/v1/commands/list', -- cgit v1.2.3-1-g7c22 From dffc5323ecd9c7bc1af0ea06ef4827078f9bcd52 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Thu, 4 Feb 2016 08:03:42 -0800 Subject: PLT-1429 Fixing code review comments --- web/react/utils/async_client.jsx | 1 - 1 file changed, 1 deletion(-) (limited to 'web/react/utils') diff --git a/web/react/utils/async_client.jsx b/web/react/utils/async_client.jsx index 970b1a4c0..328a7a7f2 100644 --- a/web/react/utils/async_client.jsx +++ b/web/react/utils/async_client.jsx @@ -787,7 +787,6 @@ export function getSuggestedCommands(command, suggestionId, component) { }); // pull out the suggested commands from the returned data - //const terms = matches.map((suggestion) => suggestion.trigger); const terms = matches.map((suggestion) => suggestion.suggestion); AppDispatcher.handleServerAction({ -- cgit v1.2.3-1-g7c22