Browse Source

couchDB addition, also custom S3

couchdb
Ruel Tmeizeh - RuhNet 3 months ago
parent
commit
2832348e19
17 changed files with 263 additions and 26 deletions
  1. +130
    -10
      app.js
  2. +2
    -1
      storages.js
  3. +4
    -0
      style/app.css
  4. +4
    -4
      submodules/couchdb/couchdb.js
  5. +13
    -0
      submodules/couchdb/i18n/en-US.json
  6. BIN
      submodules/couchdb/img/logo.png
  7. +33
    -0
      submodules/couchdb/views/formElements.html
  8. +1
    -0
      submodules/couchdb/views/logo.html
  9. +48
    -0
      submodules/custom_s3/custom_s3.js
  10. +1
    -1
      submodules/custom_s3/i18n/en-US.json
  11. BIN
      submodules/custom_s3/img/logo.png
  12. +21
    -2
      submodules/custom_s3/views/formElements.html
  13. +1
    -0
      submodules/custom_s3/views/logo.html
  14. BIN
      submodules/mts/img/logo.png
  15. +0
    -1
      submodules/mts/views/logo.html
  16. +3
    -1
      submodules/s3/i18n/en-US.json
  17. +2
    -6
      submodules/s3/views/formElements.html

+ 130
- 10
app.js View File

@ -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) {}


+ 2
- 1
storages.js View File

@ -2,7 +2,8 @@ define(function(require) {
return {
"storages": [
"s3",
"mts"
"custom_s3",
"couchdb"
]
};
});

+ 4
- 0
style/app.css View File

@ -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;


submodules/mts/mts.js → submodules/couchdb/couchdb.js View File


+ 13
- 0
submodules/couchdb/i18n/en-US.json View File

@ -0,0 +1,13 @@
{
"storage": {
"submodules": {
"couchdb": {
"nameLabel": "Name",
"bucketLabel": "IP",
"portLabel": "Port",
"keyLabel": "Username",
"secretLabel": "Password"
}
}
}
}

BIN
submodules/couchdb/img/logo.png View File

Before After
Width: 67  |  Height: 40  |  Size: 1.3 KiB

+ 33
- 0
submodules/couchdb/views/formElements.html View File

@ -0,0 +1,33 @@
<h3 class="storage-type-label">External CouchDB Storage</h3>
<hr />
<input type="hidden" name="driver" value="kazoo_couch"/>
<label class="control-group">
<span class="control-label">{{ @root.i18n.storage.submodules.couchdb.nameLabel }}</span>
<div class="controls">
<input type="text" value="{{name}}" name="name">
</div>
</label>
<label class="control-group">
<span class="control-label">{{ @root.i18n.storage.submodules.couchdb.bucketLabel }}</span>
<div class="controls">
<input type="text" value="{{settings.ip}}" name="settings.ip">
</div>
</label>
<label class="control-group">
<span class="control-label">{{ @root.i18n.storage.submodules.couchdb.portLabel }}</span>
<div class="controls">
<input type="number" value="{{settings.port}}" name="settings.port">
</div>
</label>
<label class="control-group">
<span class="control-label">{{ @root.i18n.storage.submodules.couchdb.keyLabel }}</span>
<div class="controls">
<input type="text" value="{{settings.username}}" name="settings.username">
</div>
</label>
<label class="control-group">
<span class="control-label">{{ @root.i18n.storage.submodules.couchdb.secretLabel }}</span>
<div class="controls">
<input type="password" value="{{settings.password}}" name="settings.password">
</div>
</label>

+ 1
- 0
submodules/couchdb/views/logo.html View File

@ -0,0 +1 @@
<img src="/apps/storage/submodules/couchdb/img/logo.png" alt="couchdb" />

+ 48
- 0
submodules/custom_s3/custom_s3.js View File

@ -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;
});

submodules/mts/i18n/en-US.json → submodules/custom_s3/i18n/en-US.json View File


BIN
submodules/custom_s3/img/logo.png View File

Before After
Width: 70  |  Height: 40  |  Size: 5.9 KiB

submodules/mts/views/formElements.html → submodules/custom_s3/views/formElements.html View File


+ 1
- 0
submodules/custom_s3/views/logo.html View File

@ -0,0 +1 @@
<img src="/apps/storage/submodules/custom_s3/img/logo.png" alt="custom_s3" />

BIN
submodules/mts/img/logo.png View File

Before After
Width: 112  |  Height: 40  |  Size: 18 KiB

+ 0
- 1
submodules/mts/views/logo.html View File

@ -1 +0,0 @@
<img src="/apps/storage/submodules/mts/img/logo.png" alt="mts" />

+ 3
- 1
submodules/s3/i18n/en-US.json View File

@ -3,7 +3,9 @@
"submodules": {
"s3": {
"nameLabel": "Name",
"endpointLabel": "Endpoint",
"hostLabel": "Host",
"portLabel": "Port",
"schemeLabel": "Scheme",
"bucketLabel": "Bucket",
"keyLabel": "Key",
"secretLabel": "Secret"


+ 2
- 6
submodules/s3/views/formElements.html View File

@ -1,3 +1,5 @@
<h3 class="storage-type-label">Amazon AWS S3 Object Storage</h3>
<hr />
<input type="hidden" name="handler" value="s3"/>
<label class="control-group">
<span class="control-label">{{ @root.i18n.storage.submodules.s3.nameLabel }}</span>
@ -5,12 +7,6 @@
<input type="text" value="{{name}}" name="name">
</div>
</label>
<label class="control-group">
<span class="control-label">{{ @root.i18n.storage.submodules.s3.endpointLabel }}</span>
<div class="controls">
<input type="text" value="{{settings.endpoint}}" name="settings.endpoint">
</div>
</label>
<label class="control-group">
<span class="control-label">{{ @root.i18n.storage.submodules.s3.bucketLabel }}</span>
<div class="controls">


Loading…
Cancel
Save