This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic UI to manage conversations (#33)
- Loading branch information
Showing
13 changed files
with
382 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2017 Redlink GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
'use strict'; | ||
|
||
angular | ||
.module('smartiApp') | ||
.config(function (toastrConfig) { | ||
angular.extend(toastrConfig, { | ||
autoDismiss: true, | ||
maxOpened: 2, | ||
newestOnTop: false, | ||
tapToDismiss: true, | ||
positionClass: 'toast-bottom-right' | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2017 Redlink GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
'use strict'; | ||
|
||
/** | ||
* @ngdoc function | ||
* @name smartiApp.controller:ConversationCtrl | ||
* @description | ||
* # ConversationCtrl | ||
* Controller of the smartiApp | ||
*/ | ||
angular.module('smartiApp') | ||
.controller('ConversationCtrl', function ($scope, $location, client, ConversationService) { | ||
var $ctrl = this; | ||
|
||
$ctrl.conversations = null; | ||
$ctrl.paging = { | ||
currentPage: 1, | ||
pageSize: 10, | ||
totalItems: 0 | ||
}; | ||
|
||
$ctrl.openConversation = openConversation; | ||
|
||
$scope.$watch('$ctrl.paging.currentPage', loadConversations); | ||
$scope.$watch('$ctrl.paging.pageSize', loadConversations); | ||
|
||
loadConversations(); | ||
|
||
function loadConversations() { | ||
$ctrl.conversations = null; | ||
return ConversationService.listForClient(client.data.id, $ctrl.paging.currentPage -1, $ctrl.paging.pageSize) | ||
.then(function (response) { | ||
$ctrl.paging.currentPage = response.number + 1; | ||
$ctrl.paging.pageSize = response.size; | ||
$ctrl.paging.totalItems = response.totalElements; | ||
$ctrl.conversations = response.content; | ||
|
||
return response; | ||
}); | ||
} | ||
|
||
function openConversation(conversationId) { | ||
$location.path('client/' + client.data.id + '/conversations/' + conversationId); | ||
} | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2017 Redlink GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
'use strict'; | ||
|
||
/** | ||
* @ngdoc function | ||
* @name smartiApp.controller:ConversationEditCtrl | ||
* @description | ||
* # ConversationEditCtrl | ||
* Controller of the smartiApp | ||
*/ | ||
angular.module('smartiApp') | ||
.controller('ConversationEditCtrl', function ($scope, $location, client, conversation, ConversationService, toastr) { | ||
var $ctrl = this; | ||
|
||
$ctrl.backToList = backToList; | ||
$ctrl.saveMessage = saveMessage; | ||
$ctrl.deleteMessage = deleteMessage; | ||
|
||
function backToList() { | ||
$location.path('client/' + client.data.id + '/conversations'); | ||
|
||
} | ||
|
||
function handleError(error) { | ||
if (error.status === 501) { | ||
toastr.warning('This function has not (yet) been implemented', '501 - Not Implemented'); | ||
} else { | ||
toastr.error(error.data.message, 'Error ' + error.status); | ||
} | ||
} | ||
|
||
function saveMessage(message) { | ||
return ConversationService.saveMessage(conversation.id, message).then( | ||
function (response) { | ||
conversation.messages = response.messages; | ||
}, | ||
handleError | ||
).then(function () { | ||
message.editing = false; | ||
}); | ||
} | ||
|
||
function deleteMessage(message) { | ||
return ConversationService.deleteMessage(conversation.id, message.id).then( | ||
function (response) { | ||
conversation.messages = response.messages; | ||
return response; | ||
}, | ||
handleError | ||
) | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2017 Redlink GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* @ngdoc service | ||
* @name smartiApp.ConversationService | ||
* @description | ||
* # ConversationService | ||
* Service in the smartiApp. | ||
*/ | ||
angular.module('smartiApp') | ||
.service('ConversationService', function ($http, $q, ENV) { | ||
|
||
this.listForClient = getForClient; | ||
this.getConversation = getConversation; | ||
|
||
this.saveMessage = saveMessage; | ||
this.deleteMessage = deleteMessage; | ||
|
||
function getForClient(clientId, page, pageSize) { | ||
return $http.get(ENV.serviceBaseUrl + 'admin/conversation', { | ||
params: { | ||
clientId: clientId, | ||
page: page, | ||
pageSize: pageSize | ||
} | ||
}).then(function (response) { | ||
return response.data; | ||
}); | ||
} | ||
|
||
function getConversation(conversationId) { | ||
return $http.get(ENV.serviceBaseUrl + 'admin/conversation/' + conversationId) | ||
.then(function (response) { | ||
return response.data; | ||
}); | ||
} | ||
|
||
function saveMessage(conversationId, message) { | ||
return $http.put(ENV.serviceBaseUrl + 'admin/conversation/' + conversationId + '/message/' + message.id, message) | ||
.then(function (response) { | ||
return response.data; | ||
}); | ||
} | ||
|
||
function deleteMessage(conversationId, messageId) { | ||
return $http.delete(ENV.serviceBaseUrl + 'admin/conversation/' + conversationId + '/message/' + messageId) | ||
.then(function (response) { | ||
return response.data; | ||
}); | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<!-- | ||
~ Copyright 2017 Redlink GmbH | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
~ | ||
--> | ||
<div class="clearfix"> | ||
<div class="pull-right"> | ||
<button class="btn btn-default" ng-click="$ctrl.backToList()">Back to List</button> | ||
</div> | ||
<h2>Edit conversation <span ng-bind="$resolve.conversation.id"></span></h2> | ||
</div> | ||
<div> | ||
<h3>Messages</h3> | ||
<div class="panel panel-info panel-sm" | ||
ng-repeat="m in $resolve.conversation.messages" | ||
id="#{{$index}}"> | ||
<div class="panel-heading"> | ||
#{{$index}} | ||
<span ng-bind="m.user.displayName"></span> | ||
<span class="pull-right" style="display: inline-block"> | ||
<button ng-if="m.editing" class="btn btn-default btn-xs" ng-click="$ctrl.saveMessage(m)"><i class="glyphicon glyphicon-floppy-disk"></i></button> | ||
<button ng-if="!m.editing" class="btn btn-default btn-xs" ng-click="m.editing = true"><i class="glyphicon glyphicon-pencil"></i></button> | ||
<button ng-if="!m.editing" class="btn btn-default btn-xs" ng-click="$ctrl.deleteMessage(m.id)"><i class="glyphicon glyphicon-remove"></i></button> | ||
</span> | ||
</div> | ||
<div class="panel-body"> | ||
<span ng-if="!m.editing" ng-bind="m.content"></span> | ||
<form ng-if="m.editing"> | ||
<div class="form-group"> | ||
<textarea class="form-control" ng-model="m.content"></textarea> | ||
</div> | ||
</form> | ||
</div> | ||
<div class="panel-footer"> | ||
<span ng-bind="m.time | date:'medium'"></span> | ||
</div> | ||
</div> | ||
</div> |
Oops, something went wrong.