mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-06 23:46:18 +00:00
Add settings to change contact list ordering by label/lastmsg and reverse/sort
This commit is contained in:
parent
7b92499941
commit
60bd54a12a
@ -25,6 +25,7 @@ $application->registerRoutes($this, array('routes' => array(
|
||||
array('name' => 'settings#get_settings', 'url'=> '/get/settings', 'verb' => 'GET'),
|
||||
array('name' => 'settings#set_messagelimit', 'url'=> '/set/msglimit', 'verb' => 'POST'),
|
||||
array('name' => 'settings#set_notification_state', 'url'=> '/set/notification_state', 'verb' => 'POST'),
|
||||
array('name' => 'settings#set_contact_order', 'url' => '/set/contact_order', 'verb' => 'POST'),
|
||||
|
||||
// Android API v1 doesn't have a version in the URL, be careful
|
||||
array('name' => 'api#get_api_version', 'url' => '/get/apiversion', 'verb' => 'GET'), // Android APIv1
|
||||
|
@ -42,7 +42,9 @@ class SettingsController extends Controller {
|
||||
return new JSONResponse(array("status" => true,
|
||||
"country" => $country,
|
||||
"message_limit" => $this->configMapper->getMessageLimit(),
|
||||
"notification_state" => $this->configMapper->getNotificationState()
|
||||
"notification_state" => $this->configMapper->getNotificationState(),
|
||||
"contact_order" => $this->configMapper->getContactOrder(),
|
||||
"contact_order_reverse" => $this->configMapper->getContactOrderReverse(),
|
||||
));
|
||||
}
|
||||
|
||||
@ -53,7 +55,7 @@ class SettingsController extends Controller {
|
||||
*/
|
||||
function setCountry($country) {
|
||||
if (!array_key_exists($country, CountryCodes::$codes)) {
|
||||
return new JSONResponse(array("status" => false, "msg" => "Invalid country"));
|
||||
return new JSONResponse(array("status" => false, "msg" => "Invalid country"), Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
$this->configMapper->set("country", $country);
|
||||
return new JSONResponse(array("status" => true, "msg" => "OK"));
|
||||
@ -76,9 +78,24 @@ class SettingsController extends Controller {
|
||||
*/
|
||||
function setNotificationState($notification) {
|
||||
if (!is_numeric($notification) || $notification < 0 || $notification > 2) {
|
||||
return new JSONResponse(array("status" => false, "msg" => "Invalid notification state"));
|
||||
return new JSONResponse(array("status" => false, "msg" => "Invalid notification state"), Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
$this->configMapper->set("notification_state", $notification);
|
||||
return new JSONResponse(array("status" => true, "msg" => "OK"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @param $attribute
|
||||
* @param $reverse
|
||||
* @return JSONResponse
|
||||
*/
|
||||
function setContactOrder($attribute, $reverse) {
|
||||
if (!in_array($reverse, ['true','false']) || !in_array($attribute, ['lastmsg','label'])) {
|
||||
return new JSONResponse(array("status" => false, "msg" => "Invalid contact ordering"), Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
$this->configMapper->set("contact_order", $attribute);
|
||||
$this->configMapper->set("contact_order_reverse", $reverse);
|
||||
return new JSONResponse(array("status" => true, "msg" => "OK"));
|
||||
}
|
||||
}
|
||||
|
@ -95,6 +95,22 @@ class ConfigMapper extends Mapper {
|
||||
}
|
||||
return $st;
|
||||
}
|
||||
|
||||
public function getContactOrder() {
|
||||
$order = $this->getKey("contact_order");
|
||||
if ($order === false) {
|
||||
$order = "lastmsg";
|
||||
}
|
||||
return $order;
|
||||
}
|
||||
|
||||
public function getContactOrderReverse() {
|
||||
$rev = $this->getKey("contact_order_reverse");
|
||||
if ($rev === false) {
|
||||
$rev = "true";
|
||||
}
|
||||
return $rev;
|
||||
}
|
||||
};
|
||||
|
||||
?>
|
||||
|
@ -30,6 +30,27 @@ function arrayUnique(arr) {
|
||||
});
|
||||
}
|
||||
|
||||
function toBool(str) {
|
||||
if (str === "true") {
|
||||
return true;
|
||||
}
|
||||
else if (str === "false") {
|
||||
return false;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
app.directive('toInt', function() {
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function(scope, element, attrs, modelCtrl) {
|
||||
modelCtrl.$parsers.push(function (inputValue) {
|
||||
return parseInt(inputValue, 10);
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
// Imported from ownCloud contact app
|
||||
app.filter('peerColor', function() {
|
||||
return function(input) {
|
||||
@ -70,6 +91,8 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
||||
|
||||
$scope.setting_msgLimit = 100;
|
||||
$scope.setting_enableNotifications = 1;
|
||||
$scope.setting_contactOrder = 'lastmsg';
|
||||
$scope.setting_contactOrderReverse = true;
|
||||
|
||||
$scope.contacts = [];
|
||||
$scope.messages = [];
|
||||
@ -97,6 +120,15 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
||||
$.post(OC.generateUrl('/apps/ocsms/set/notification_state'),{'notification': $scope.setting_enableNotifications});
|
||||
};
|
||||
|
||||
$scope.setContactOrderSetting = function () {
|
||||
$.post(OC.generateUrl('/apps/ocsms/set/contact_order'),
|
||||
{
|
||||
'attribute': $scope.setting_contactOrder,
|
||||
'reverse': $scope.setting_contactOrderReverse
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// Conversations
|
||||
$scope.loadConversation = function (contact) {
|
||||
OC.Util.History.pushState('phonenumber=' + contact.nav);
|
||||
@ -314,9 +346,13 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
||||
|
||||
$('input[name=setting_msg_per_page]').val(jsondata["message_limit"]);
|
||||
$('select[name=setting_notif]').val(jsondata["notification_state"]);
|
||||
$('select[name=setting_contact_order]').val(jsondata["contact_order"]);
|
||||
$('input[name=setting_contact_order_reverse').val(toBool(jsondata["contact_order_reverse"]));
|
||||
|
||||
$scope.setting_msgLimit = jsondata["message_limit"];
|
||||
$scope.setting_enableNotifications = jsondata["notification_state"];
|
||||
$scope.setting_contactOrder = jsondata["contact_order"];
|
||||
$scope.setting_contactOrderReverse = toBool(jsondata["contact_order_reverse"]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -9,7 +9,7 @@ use \OCA\OcSms\Lib\CountryCodes;
|
||||
<div class="ng-scope" id="app" ng-app="OcSms" ng-controller="OcSmsController">
|
||||
<div id="app-mailbox-peers">
|
||||
<ul class="contact-list">
|
||||
<li ng-repeat="contact in contacts | orderBy:'-lastmsg'" peer-label="{{ contact.label }}" ng-click="loadConversation(contact);" href="#">
|
||||
<li ng-repeat="contact in contacts | orderBy:setting_contactOrder:setting_contactOrderReverse" peer-label="{{ contact.label }}" ng-click="loadConversation(contact);" href="#">
|
||||
<img class="ocsms-plavatar" ng-src="{{ contact.avatar }}" ng-show="contact.avatar !== undefined" />
|
||||
<div class="ocsms-plavatar" ng-show="contact.avatar === undefined" ng-style="{'background-color': (contact.label | peerColor)}">{{ contact.label | firstCharacter }}</div>
|
||||
<a class="ocsms-plname" style="{{ contact.unread > 0 ? 'font-weight:bold;' : ''}}" mailbox-label="{{ contact.label }}" mailbox-navigation="{{ contact.nav }}">{{ contact.label }}{{ contact.unread > 0 ? ' (' + contact.unread + ') ' : '' }}</a>
|
||||
@ -22,25 +22,35 @@ use \OCA\OcSms\Lib\CountryCodes;
|
||||
</div>
|
||||
<div id="app-settings-content">
|
||||
<div><label for="setting_msg_per_page">Max messages on tab loading</label>
|
||||
<input type="number" min="10" max="10000" name="setting_msg_per_page" ng-model="setting_msgLimit" ng-change="setMessageLimit()" />
|
||||
<span class="label-invalid-input" ng-if="setting_msgLimit == null || setting_msgLimit == undefined">Invalid message limit</span>
|
||||
<input type="number" min="10" max="10000" name="setting_msg_per_page" ng-model="setting_msgLimit" ng-change="setMessageLimit()" to-int />
|
||||
<span class="label-invalid-input" ng-if="setting_msgLimit == null || setting_msgLimit == undefined">Invalid message limit</span>
|
||||
</div>
|
||||
|
||||
<div><label for="intl_phone">Country code</label>
|
||||
<select name="intl_phone" id="sel_intl_phone">
|
||||
<?php foreach (CountryCodes::$codes as $code => $cval) { ?>
|
||||
<option><?php p($code); ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<button class="new-button primary icon-checkmark-white" ng-click="sendCountry();"></button>
|
||||
<select name="intl_phone" id="sel_intl_phone">
|
||||
<?php foreach (CountryCodes::$codes as $code => $cval) { ?>
|
||||
<option><?php p($code); ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<button class="new-button primary icon-checkmark-white" ng-click="sendCountry();"></button>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for"setting_notif">Notification settings</label>
|
||||
<select name="setting_notif" ng-model="setting_enableNotifications" ng-change="setNotificationSetting()">
|
||||
<option value="1">Enable</option>
|
||||
<option value="0">Disable</option>
|
||||
</select>
|
||||
<label for="setting_contact_order">Contact ordering</label>
|
||||
<select name="setting_contact_order" ng-model="setting_contactOrder" ng-change="setContactOrderSetting()">
|
||||
<option value="lastmsg">Last message</option>
|
||||
<option value="label">Label</option>
|
||||
</select>
|
||||
<label for "setting_contact_order_reverse">Reverse ?</label>
|
||||
<input type="checkbox" ng-model="setting_contactOrderReverse" ng-change="setContactOrderSetting()" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for"setting_notif">Notification settings</label>
|
||||
<select name="setting_notif" ng-model="setting_enableNotifications" ng-change="setNotificationSetting()">
|
||||
<option value="1">Enable</option>
|
||||
<option value="0">Disable</option>
|
||||
</select>
|
||||
</div>
|
||||
</div> <!-- app-settings-content -->
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user