diff --git a/README.md b/README.md
index 0f1fc2b..4d897e2 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
# daster
-Управление диалпланом
+Dialplan Asterisk - управление диалпланом
+
+![mainpage](images/mainpage.png)
diff --git a/images/mainpage.png b/images/mainpage.png
new file mode 100644
index 0000000..d5cf9bf
Binary files /dev/null and b/images/mainpage.png differ
diff --git a/js/script.js b/js/script.js
index 2dc6f90..711df54 100644
--- a/js/script.js
+++ b/js/script.js
@@ -1,11 +1,10 @@
+var numbers = [];
+
$(document).ready(function () {
message = new Message;
- // (new divNotFoundNumbers).push("Загрузка...");
-
$("button").button();
$("#tabs").tabs();
- // $("#accordion-numbers").accordion();
// $(".addNumber").click(() => {
// numberAdd()
@@ -13,12 +12,19 @@ $(document).ready(function () {
$("body").fadeTo(500, 1);
- // getData("Список номеров успешно загружен");
-
$(".search").on("input", function () {
- // showNumbers(numbers.filter(e => e.id.includes($(this).val())))
+ showNumbers(
+ $("#accordion-numbers .ui-accordion-content-active"),
+ numbers.filter(e => e.number.includes($(this).val()))
+ )
+ }).on("focus", function () {
+ if ($(this).val())
+ showNumbers(
+ $("#accordion-numbers .ui-accordion-content-active"),
+ numbers.filter(e => e.number.includes($(this).val()))
+ );
}).keydown(function (e) {
- // e.key == "Escape" && ($(this).val(""), showNumbers())
+ e.key == "Escape" && ($(this).val(""), showNumbers($("#accordion-numbers .ui-accordion-content-active")))
});
loadData();
@@ -52,7 +58,7 @@ function isJSON(str) {
}
function loadData() {
- request('listsgroups', 'json').then(data => {
+ request('listsgroups', 'text').then(data => {
data.error ? message.error(data.message) : generateListsGroups(data);
}).catch(error => {
message.error(error.message);
@@ -60,12 +66,7 @@ function loadData() {
}
function generateListsGroups(data) {
- let numbers = $("#tabs-numbers");
- let group = $('
');
- $(data).each((i, j) => {
- group.append(`${j.comment}
`);
- });
- numbers.append(group);
+ $("#tabs-numbers").html(data);
$("#accordion-numbers").accordion({
heightStyle: "content",
create: function( event, ui ) {
@@ -78,13 +79,57 @@ function generateListsGroups(data) {
}
async function generateGroupNumbers(panel) {
- request('groupnumbers', 'text', { group: panel.data("group-name") }).then(data => {
+ request('groupnumbers', 'json', { group: panel.data("group-name") }).then(data => {
if (isJSON(data) && JSON.parse(data).error)
message.error(JSON.parse(data).message);
else {
- panel.html(data);
+ numbers = data;
+ showNumbers(panel);
}
}).catch(error => {
message.error(error.message);
});
}
+
+function showNumbers(panel, data = numbers) {
+ (new divNotFoundNumbers).remove();
+ let body = panel.find('.body').html('');
+ $(data).each((i, j) => {
+ let row = $(`
`);
+ row.append(`${j.number} | `);
+ row.append(`${j.list} | `);
+ row.append(`${j.all_cc} | `);
+ row.append(`${j.white_cc} | `);
+ row.append(`${j.black_cc} | `);
+ row.append(`${j.comment} | `);
+ body.append(row);
+
+ row.click(function(){
+ // numberEdit($(this).data('number'));
+ });
+ });
+
+ if (!body.children().length)
+ (new divNotFoundNumbers).push();
+}
+
+
+function divNotFoundNumbers() {
+ let notFound = $('.failNumbers');
+ let divTable = $('.body-rows');
+ let divFound = $('');
+
+ divFound.css({
+ "color": "#333",
+ "text-align": "center",
+ "padding": "20px 0 20px 0"
+ });
+
+ this.push = function(text = 'Нет номеров') {
+ divTable.append(divFound.html(text));
+ }
+
+ this.remove = function() {
+ notFound.remove();
+ }
+}
diff --git a/source/requests/groupnumbers.d b/source/requests/groupnumbers.d
index 4634a38..62f6288 100644
--- a/source/requests/groupnumbers.d
+++ b/source/requests/groupnumbers.d
@@ -7,6 +7,5 @@ import singlog;
void groupnumbers(HTTPServerRequest req, HTTPServerResponse res) {
auto jsr = req.json;
- auto listNumbers = getListNumbers(jsr["group"].get!string);
- render!("group-numbers-list.dt", listNumbers)(res);
+ res.writeJsonBody(getListNumbers(jsr["group"].get!string).serializeToJson());
}
diff --git a/source/requests/listsgroups.d b/source/requests/listsgroups.d
index be1504c..4d6bec3 100644
--- a/source/requests/listsgroups.d
+++ b/source/requests/listsgroups.d
@@ -5,7 +5,6 @@ import response;
import data;
void listsgroups(HTTPServerRequest req, HTTPServerResponse res) {
- // auto jsr = req.json;
-
- res.writeJsonBody(getListGroups().serializeToJson());
+ auto listGroups = getListGroups();
+ render!("group-numbers-list.dt", listGroups)(res);
}
diff --git a/source/version_.d b/source/version_.d
index ea9a3a6..7164ef0 100644
--- a/source/version_.d
+++ b/source/version_.d
@@ -1,3 +1,3 @@
module version_;
-enum dasterVersion = "v0.0.1";
+enum dasterVersion = "v0.0.2";
diff --git a/views/group-numbers-list.dt b/views/group-numbers-list.dt
index 46d56eb..d5cc975 100644
--- a/views/group-numbers-list.dt
+++ b/views/group-numbers-list.dt
@@ -1,22 +1,18 @@
- import structures;
-table
- thead.head
- tr
- th Номер
- th Список
- th Общие звонки
- th Белые звонки
- th Черные звонки
- th Комментарий
-div.body-rows
- table
- tbody.body
- - foreach (number; listNumbers)
- tr.row
- td #{number.number}
- td #{number.list}
- td #{number.all_cc}
- td #{number.white_cc}
- td #{number.black_cc}
- td #{number.comment}
+div#accordion-numbers
+ - foreach (group; listGroups)
+ h3 #{group.comment}
+ div.group-content(data-group-name='#{group.name}')
+ table
+ thead.head
+ tr
+ th Номер
+ th Список
+ th Общие звонки
+ th Белые звонки
+ th Черные звонки
+ th Комментарий
+ div.body-rows
+ table
+ tbody.body