diff --git a/app.js b/app.js index efb7c5b..24c3fa5 100644 --- a/app.js +++ b/app.js @@ -60,6 +60,9 @@ define(function(require) { render: function(container) { var self = this; +console.log("STORAGES:"); +console.log(self.storages); + monster.pub('storage.fetchStorages', { storages: self.storages, callback: function (args) { @@ -119,7 +122,10 @@ define(function(require) { self.getStorage(function(data) { var storagesData = self.storageManagerFormatData(data); for (var i = 0, len = storagesData.length; i < len; i++) { - storagesData[i].logo = self.storages[storagesData[i].type].getLogo() + //storagesData[i].logo = self.storages[storagesData[i].type].getLogo() + var storageType = storagesData[i].type; + + storagesData[i].logo = self.storages[storageType].getLogo() } log('Storages List:'); @@ -194,6 +200,31 @@ define(function(require) { }); }, + formatAttachmentSettings: function(storageData) { + var type = ""; + var attachments = storageData.attachments; + + if(storageData.hasOwnProperty('connections')) { //type is couchdb + attachments = storageData.connections; + type = "couchdb"; + } + + var attachments = storageData.attachments; + for(var i in attachments) if(attachments.hasOwnProperty(i)) { + var thisItem = attachments[i]; + var settings = thisItem.settings; + if (thisItem.settings && thisItem.settings.port) { + thisItem.settings.port = Number(thisItem.settings.port); + } else { + thisItem.settings.port = 443; + if (type == "couchdb") thisItem.settings.port = 5984; + } + attachments[i] = thisItem; + }; + storageData.attachments = attachments; + return storageData; + }, + storageManagerUpdateStorage: function(storageData, callback) { var self = this; @@ -207,7 +238,7 @@ define(function(require) { data: { accountId: self.accountId, removeMetadataAPI: true, // or generateError: false - data: storageData + data: self.formatAttachmentSettings(storageData) }, success: function(data, status) { if(typeof(callback) === 'function') { @@ -237,7 +268,7 @@ define(function(require) { data: { accountId: self.accountId, removeMetadataAPI: true, // or generateError: false - data: storageData + data: self.formatAttachmentSettings(storageData) }, success: function(data, status) { if(typeof(callback) === 'function') { @@ -256,20 +287,59 @@ define(function(require) { storageManagerFormatData: function(data) { var activeStorageId = null; + var storageType = ""; try { //activeStorageId = data.plan.modb.connection; //.handler; + if(data && data.hasOwnProperty('plan') && data.plan.hasOwnProperty('modb') && data.plan.modb.hasOwnProperty('connection') ) { + activeStorageId = data.plan.modb.connection; //.handler; + storageType = "couchdb"; + } else { activeStorageId = data.plan.modb.types.call_recording.attachments.handler; + } } catch(e) { log('Active storage not found'); } var itemData; var storagesList = []; + if (storageType == "couchdb" && data && data.hasOwnProperty('connections') && Object.keys(data.connections).length > 0) { + var connections = data.connections; + for(var i in connections) if(connections.hasOwnProperty(i)) { + itemData = { + id: i, +// type: connections[i].handler, +// type: connections[i], + type: storageType, //"couchdb" + name: connections[i].name, + settings: connections[i].settings, + isActive: false + }; + + if(activeStorageId && itemData.id === activeStorageId) { + itemData.isActive = true; + } + storagesList.push(itemData) + } + } if(data && data.hasOwnProperty('attachments') && Object.keys(data.attachments).length > 0) { var attachments = data.attachments; + for(var i in attachments) if(attachments.hasOwnProperty(i)) { + var storageType = attachments[i].handler; + var settings = attachments[i].settings; + //get custom s3 type by checking if URL is not AWS + if (storageType == "s3" + && ( + (settings.hasOwnProperty('host') && settings.host != "s3.amazonaws.com" && settings.host != "") + || (settings.hasOwnProperty('port') && settings.port != "443" && settings.port != 443 && settings.port != "") + ) + ) { + storageType = "custom_s3"; + } + itemData = { id: i, - type: attachments[i].handler, + //type: attachments[i].handler, + type: storageType, name: attachments[i].name, settings: attachments[i].settings, isActive: false @@ -301,8 +371,10 @@ define(function(require) { .find('.js-item-settings-wrapper') .hide(); - if(data.attachments.hasOwnProperty(uuid)) { + if(data.attachments && data.attachments.hasOwnProperty(uuid)) { var storageData = data.attachments[uuid]; + } else if(data.connections && data.connections.hasOwnProperty(uuid)) { + var storageData = data.connections[uuid]; } var template = self.getTemplate({ @@ -360,7 +432,8 @@ define(function(require) { if(isAlreadyActive) { self.storageManagerShowMessage(self.i18n.active().storage.alreadyActiveMessage, 'warning') } else { - self.storageManagerSetDefaultStorage(uuid); + var storageType = $(this).closest('.js-storage-item').data('type'); + self.storageManagerSetDefaultStorage(uuid, storageType); } }); }, @@ -421,7 +494,7 @@ define(function(require) { }; if(isNeedSetDefault) { - self.storageManagerSetDefaultStorage(newUuid, function () { + self.storageManagerSetDefaultStorage(newUuid, typeKeyword, function () { self.storageManagerRender(renderArgs); }); } else { @@ -449,22 +522,60 @@ define(function(require) { } if(storageKeyword && self.storages.hasOwnProperty(storageKeyword)) { + if (storageKeyword == "couchdb") { + storageData["connections"] = {}; + data.settings.port = eval(data.settings.port); + storageData.connections[uuid] = data; + } else { storageData.attachments[uuid] = data; + } return storageData; } else { monster.ui.alert('Please install storage correctly (' + storageKeyword + ')'); } }, - storageManagerSetDefaultStorage: function(uuid, callback) { + storageManagerSetDefaultStorage: function(uuid, storageType, callback) { var self = this; if(!monster.util.isAdmin()) { log('Permission error. Use admin account for change storage settings'); return; } + var newData = {}; + if (storageType == "couchdb") { + newData = { + plan: { + modb: { + connection: uuid, + types: { + call_recording: { + database:{ + create_options:{} + } + }, + mailbox_message: { + database:{ + create_options:{} + } + } + } + } +// account: { +// types: { +// media: { +// database:{ +// create_options:{} +// } +// } +// } +// }, + } + }; + - var newData = { + } else { + newData = { plan: { modb: { types: { @@ -491,7 +602,7 @@ define(function(require) { }, } }; - + } self.storageManagerPatchStorage(newData, function(data) { $('#storage_manager_wrapper').find('.js-storage-item') @@ -547,12 +658,19 @@ define(function(require) { self.getStorage(function(storagesData) { var resultData = {}; + if(storagesData.hasOwnProperty('connections')) { + resultData.connections = storagesData.connections; + } if(storagesData.hasOwnProperty('attachments')) { resultData.attachments = storagesData.attachments; } if(storagesData.hasOwnProperty('plan')) { resultData.plan = storagesData.plan; } + if(resultData.connections && resultData.connections.hasOwnProperty(uuid)) { + resultData.attachments = {}; + delete resultData.connections[uuid]; + } if(resultData.attachments && resultData.attachments.hasOwnProperty(uuid)) { delete resultData.attachments[uuid]; @@ -561,6 +679,8 @@ define(function(require) { try { if(resultData.plan.modb.types.call_recording.attachments.handler === uuid) { resultData.plan = {}; + } else if(resultData.plan.modb.types.call_recording.connection === uuid) { + resultData.plan = {}; } } catch (e) {} diff --git a/storages.js b/storages.js index 3339764..f1213e5 100644 --- a/storages.js +++ b/storages.js @@ -2,7 +2,8 @@ define(function(require) { return { "storages": [ "s3", - "mts" + "custom_s3", + "couchdb" ] }; }); diff --git a/style/app.css b/style/app.css index e8ed3e3..e67787b 100644 --- a/style/app.css +++ b/style/app.css @@ -172,6 +172,10 @@ .storage-item-settings .storage-item-logo img, .storage-item-settings .storage-item-logo svg { max-height: 40px; } +.storage-item-settings .storage-type-label { + text-align: center; +} + .storage-item-settings .form-horizontal { margin: 0 auto; display: block; diff --git a/submodules/mts/mts.js b/submodules/couchdb/couchdb.js similarity index 82% rename from submodules/mts/mts.js rename to submodules/couchdb/couchdb.js index f721416..2527fc6 100644 --- a/submodules/mts/mts.js +++ b/submodules/couchdb/couchdb.js @@ -2,7 +2,7 @@ define(function(require){ var $ = require('jquery'); const CONFIG = { - submoduleName: 'mts', + submoduleName: 'couchdb', i18n: [ 'en-US' ] }; @@ -10,10 +10,10 @@ define(function(require){ requests: {}, subscribe: { - 'storage.fetchStorages': 'defineStorageMTS' + 'storage.fetchStorages': 'defineStorageCouchDB' }, - defineStorageMTS: function(args) { + defineStorageCouchDB: function(args) { var self = this, storage_nodes = args.storages; @@ -36,7 +36,7 @@ define(function(require){ }; $.extend(true, storage_nodes, { - 'mts': methods + 'couchdb': methods } ); diff --git a/submodules/couchdb/i18n/en-US.json b/submodules/couchdb/i18n/en-US.json new file mode 100644 index 0000000..ff5d93a --- /dev/null +++ b/submodules/couchdb/i18n/en-US.json @@ -0,0 +1,13 @@ +{ + "storage": { + "submodules": { + "couchdb": { + "nameLabel": "Name", + "bucketLabel": "IP", + "portLabel": "Port", + "keyLabel": "Username", + "secretLabel": "Password" + } + } + } +} diff --git a/submodules/couchdb/img/logo.png b/submodules/couchdb/img/logo.png new file mode 100644 index 0000000..0bc7c15 Binary files /dev/null and b/submodules/couchdb/img/logo.png differ diff --git a/submodules/couchdb/views/formElements.html b/submodules/couchdb/views/formElements.html new file mode 100644 index 0000000..0536b08 --- /dev/null +++ b/submodules/couchdb/views/formElements.html @@ -0,0 +1,33 @@ +

External CouchDB Storage

+
+ + + + + + diff --git a/submodules/couchdb/views/logo.html b/submodules/couchdb/views/logo.html new file mode 100644 index 0000000..a857582 --- /dev/null +++ b/submodules/couchdb/views/logo.html @@ -0,0 +1 @@ +couchdb diff --git a/submodules/custom_s3/custom_s3.js b/submodules/custom_s3/custom_s3.js new file mode 100644 index 0000000..fef6bbe --- /dev/null +++ b/submodules/custom_s3/custom_s3.js @@ -0,0 +1,48 @@ +define(function(require){ + var $ = require('jquery'); + + const CONFIG = { + submoduleName: 'custom_s3', + i18n: [ 'en-US' ] + }; + + var app = { + requests: {}, + + subscribe: { + 'storage.fetchStorages': 'defineStorageCustomS3' + }, + + defineStorageCustomS3: function(args) { + var self = this, + storage_nodes = args.storages; + + var methods = { + getLogo: function () { + return self.getTemplate({ + name: 'logo', + submodule: CONFIG.submoduleName, + data: {} + }); + }, + + getFormElements: function (storageData) { + return self.getTemplate({ + name: 'formElements', + submodule: CONFIG.submoduleName, + data: storageData + }); + } + }; + + $.extend(true, storage_nodes, { + 'custom_s3': methods + } + ); + + args.callback && args.callback(CONFIG) + } + }; + + return app; +}); diff --git a/submodules/mts/i18n/en-US.json b/submodules/custom_s3/i18n/en-US.json similarity index 89% rename from submodules/mts/i18n/en-US.json rename to submodules/custom_s3/i18n/en-US.json index 6f31f71..4c22635 100644 --- a/submodules/mts/i18n/en-US.json +++ b/submodules/custom_s3/i18n/en-US.json @@ -1,7 +1,7 @@ { "storage": { "submodules": { - "mts": { + "custom_s3": { "nameLabel": "Name", "bucketLabel": "Bucket", "keyLabel": "Key", diff --git a/submodules/custom_s3/img/logo.png b/submodules/custom_s3/img/logo.png new file mode 100644 index 0000000..f4bfce2 Binary files /dev/null and b/submodules/custom_s3/img/logo.png differ diff --git a/submodules/mts/views/formElements.html b/submodules/custom_s3/views/formElements.html similarity index 51% rename from submodules/mts/views/formElements.html rename to submodules/custom_s3/views/formElements.html index 08220f2..4486ade 100644 --- a/submodules/mts/views/formElements.html +++ b/submodules/custom_s3/views/formElements.html @@ -1,5 +1,6 @@ +

Custom S3–Compatible Object Storage

+
- -