Skip to content

Commit 333f962

Browse files
committed
Merge pull request #6 from sakshityagi/master
Done the enhancements of Chat color and Auto save API keys
2 parents 8ae3ddc + b4a67aa commit 333f962

16 files changed

Lines changed: 378 additions & 23 deletions

File tree

control/design/app.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
'use strict';
2+
3+
(function (angular, buildfire) {
4+
angular.module('smoochChatPluginDesign', ['ui.bootstrap'])
5+
.controller('DesignHomeCtrl', ['$scope', 'Buildfire', 'STATUS_CODE', 'TAG_NAMES', 'DataStore', function ($scope, Buildfire, STATUS_CODE, TAG_NAMES, DataStore) {
6+
var DesignHome = this;
7+
DesignHome.data = {
8+
settings: {
9+
"apiKey": "",
10+
"headerText": ""
11+
},
12+
design:{
13+
color:""
14+
}
15+
};
16+
DesignHome.color = {
17+
design:[
18+
{ name:"5d8aa8"},
19+
{ name:"007fff"},
20+
{ name:"9966cc"},
21+
{ name:"98777b"},
22+
{ name:"a4c639"},
23+
{ name:"e52b50"},
24+
{ name:"e32636"},
25+
]
26+
};
27+
28+
/*Init method call, it will bring all the pre saved data*/
29+
DesignHome.init = function () {
30+
DesignHome.success = function (result) {
31+
console.info('init success result:', result);
32+
if (result) {
33+
DesignHome.data = result.data;
34+
if (!DesignHome.data.design) {
35+
DesignHome.data.design = {};
36+
DesignHome.data.design.color = DesignHome.color.design[0].name;
37+
}
38+
}
39+
};
40+
DesignHome.error = function (err) {
41+
if (err && err.code !== STATUS_CODE.NOT_FOUND) {
42+
console.error('Error while getting data', err);
43+
}
44+
else if (err && err.code === STATUS_CODE.NOT_FOUND) {
45+
DesignHome.saveData(JSON.parse(angular.toJson(DesignHome.data)), TAG_NAMES.SMOOCH_CHAT_INFO);
46+
}
47+
};
48+
DataStore.get(TAG_NAMES.SMOOCH_CHAT_INFO).then(DesignHome.success, DesignHome.error);
49+
};
50+
DesignHome.init();
51+
52+
DesignHome.saveData = function (newObj, tag) {
53+
if (typeof newObj === 'undefined') {
54+
return;
55+
}
56+
DesignHome.success = function (result) {
57+
console.info('Saved data result: ', result);
58+
};
59+
DesignHome.error = function (err) {
60+
console.error('Error while saving data : ', err);
61+
};
62+
DataStore.save(newObj, tag).then(DesignHome.success, DesignHome.error);
63+
};
64+
65+
DesignHome.changeColor = function (color) {
66+
DesignHome.data.design.color = color;
67+
DesignHome.saveData(JSON.parse(angular.toJson(DesignHome.data)), TAG_NAMES.SMOOCH_CHAT_INFO);
68+
};
69+
70+
DesignHome.gotToPage = function(){
71+
window.open('https://app.smooch.io/signup', '_blank');
72+
};
73+
}])
74+
})(window.angular, window.buildfire);

control/design/app.services.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'use strict';
2+
3+
(function (angular, buildfire) {
4+
angular.module('smoochChatPluginDesign')
5+
.provider('Buildfire', [function () {
6+
var Buildfire = this;
7+
Buildfire.$get = function () {
8+
return buildfire
9+
};
10+
return Buildfire;
11+
}])
12+
.factory("DataStore", ['Buildfire', '$q', 'STATUS_CODE', 'STATUS_MESSAGES', function (Buildfire, $q, STATUS_CODE, STATUS_MESSAGES) {
13+
return {
14+
get: function (_tagName) {
15+
var deferred = $q.defer();
16+
Buildfire.datastore.get(_tagName, function (err, result) {
17+
if (err) {
18+
return deferred.reject(err);
19+
} else if (result) {
20+
return deferred.resolve(result);
21+
}
22+
});
23+
return deferred.promise;
24+
}, update: function (_id, _item, _tagName) {
25+
var deferred = $q.defer();
26+
if (typeof _id == 'undefined') {
27+
return deferred.reject(new Error({
28+
code: STATUS_CODE.UNDEFINED_ID,
29+
message: STATUS_MESSAGES.UNDEFINED_ID
30+
}));
31+
}
32+
if (typeof _item == 'undefined') {
33+
return deferred.reject(new Error({
34+
code: STATUS_CODE.UNDEFINED_DATA,
35+
message: STATUS_MESSAGES.UNDEFINED_DATA
36+
}));
37+
}
38+
Buildfire.datastore.update(_id, _item, _tagName, function (err, result) {
39+
if (err) {
40+
return deferred.reject(err);
41+
} else if (result) {
42+
return deferred.resolve(result);
43+
}
44+
});
45+
return deferred.promise;
46+
},
47+
save: function (_item, _tagName) {
48+
var deferred = $q.defer();
49+
if (typeof _item == 'undefined') {
50+
return deferred.reject(new Error({
51+
code: STATUS_CODE.UNDEFINED_DATA,
52+
message: STATUS_MESSAGES.UNDEFINED_DATA
53+
}));
54+
}
55+
Buildfire.datastore.save(_item, _tagName, function (err, result) {
56+
if (err) {
57+
return deferred.reject(err);
58+
} else if (result) {
59+
return deferred.resolve(result);
60+
}
61+
});
62+
return deferred.promise;
63+
}
64+
}
65+
}])
66+
})(window.angular, window.buildfire);
160 Bytes
Loading
171 Bytes
Loading
150 Bytes
Loading
168 Bytes
Loading
168 Bytes
Loading
173 Bytes
Loading
174 Bytes
Loading

control/design/enums.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
(function (angular) {
4+
angular.module('smoochChatPluginDesign')
5+
.constant('TAG_NAMES', {
6+
SMOOCH_CHAT_INFO: 'smoochChatInfo'
7+
})
8+
.constant('STATUS_CODE', {
9+
INSERTED: 'inserted',
10+
UPDATED: 'updated',
11+
NOT_FOUND: 'NOTFOUND',
12+
UNDEFINED_DATA: 'UNDEFINED_DATA',
13+
UNDEFINED_OPTIONS: 'UNDEFINED_OPTIONS',
14+
UNDEFINED_ID: 'UNDEFINED_ID',
15+
ITEM_ARRAY_FOUND: 'ITEM_ARRAY_FOUND',
16+
NOT_ITEM_ARRAY: 'NOT_ITEM_ARRAY'
17+
})
18+
.constant('STATUS_MESSAGES', {
19+
UNDEFINED_DATA: 'Undefined data provided',
20+
UNDEFINED_OPTIONS: 'Undefined options provided',
21+
UNDEFINED_ID: 'Undefined id provided',
22+
NOT_ITEM_ARRAY: 'Array of Items not provided',
23+
ITEM_ARRAY_FOUND: 'Array of Items provided'
24+
})
25+
.constant('PROXY_SERVER', {
26+
serverUrl: "http://proxy.buildfire.com"
27+
});
28+
})(window.angular);

0 commit comments

Comments
 (0)