Skip to content

Commit 2a3e3c7

Browse files
committed
Finished refactoring withing eslint rules. Switched on eslint in webpack config.
1 parent 87b1d64 commit 2a3e3c7

12 files changed

+199
-179
lines changed

.eslintrc

-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"no-empty": 2,
3535
"no-empty-pattern": 2,
3636
"no-eq-null": 2,
37-
"no-eval": 2,
3837
"no-extend-native": 2,
3938
"no-fallthrough": 2,
4039
"no-floating-decimal": 2,
@@ -65,7 +64,6 @@
6564
"no-shadow-restricted-names": 2,
6665
"no-shadow": 2,
6766
"no-undef": [2, { "typeof": true }],
68-
"no-undefined": 2,
6967
"no-use-before-define": [2, "nofunc"],
7068
"no-path-concat": 2,
7169
"brace-style": 2,

src/app/common/db/db.service.js

+52-58
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,11 @@ const deps = [
99
export default angular.module('db', deps)
1010
.factory('dbService', function CollectionService($q, Loki) {
1111
'ngInject';
12-
12+
1313
let _db;
14-
let _collections;
14+
let _collections = {};
1515
initDB();
1616

17-
return {
18-
getCollections,
19-
getCollection,
20-
addCollection,
21-
updateCollection,
22-
deleteCollection
23-
};
24-
2517
/**
2618
* Init database
2719
*/
@@ -33,60 +25,62 @@ export default angular.module('db', deps)
3325
});
3426
}
3527

36-
/**
37-
* Returned all collections
38-
* @returns {*}
39-
*/
40-
function getCollections() {
41-
return $q((resolve, reject) => {
42-
let options = {
43-
collections: {
44-
proto: Object
45-
}
46-
};
28+
return {
29+
/**
30+
* Returned all collections
31+
* @returns {*} promise
32+
*/
33+
getCollections() {
34+
return $q(resolve => {
35+
const options = {
36+
collections: {
37+
proto: Object
38+
}
39+
};
4740

48-
_db.loadDatabase(options, () => {
49-
_collections = _db.getCollection('collections');
41+
_db.loadDatabase(options, () => {
42+
_collections = _db.getCollection('collections');
5043

51-
if (!_collections) {
52-
_collections = _db.addCollection('collections', {autoupdate: true});
53-
}
44+
if (!_collections) {
45+
_collections = _db.addCollection('collections', {autoupdate: true});
46+
}
5447

55-
resolve(_collections.data);
48+
resolve(_collections.data);
49+
});
5650
});
57-
});
58-
}
51+
},
5952

60-
/**
61-
* Returned collection by id
62-
* @param {int} id
63-
* @returns {*}
64-
*/
65-
function getCollection(id) {
66-
return _collections.get(id);
67-
}
53+
/**
54+
* Returned collection by id
55+
* @param {int} id Collection id
56+
* @returns {object} Collection object
57+
*/
58+
getCollection(id) {
59+
return _collections.get(id);
60+
},
6861

69-
/**
70-
* Add new collection
71-
* @param {object} collection
72-
*/
73-
function addCollection(collection) {
74-
_collections.insert(collection);
75-
}
62+
/**
63+
* Add new collection
64+
* @param {object} collection New collection
65+
*/
66+
addCollection(collection) {
67+
_collections.insert(collection);
68+
},
7669

77-
/**
78-
* Update collection data
79-
* @param {object} collection
80-
*/
81-
function updateCollection(collection) {
82-
_collections.update(collection);
83-
}
70+
/**
71+
* Update collection data
72+
* @param {object} collection Collection object
73+
*/
74+
updateCollection(collection) {
75+
_collections.update(collection);
76+
},
8477

85-
/**
86-
* Delete collection
87-
* @param {object} collection
88-
*/
89-
function deleteCollection(collection) {
90-
_collections.remove(collection);
91-
}
78+
/**
79+
* Delete collection
80+
* @param {object} collection Collection object
81+
*/
82+
deleteCollection(collection) {
83+
_collections.remove(collection);
84+
}
85+
};
9286
});

src/app/common/google-translate/google-translate.service.js

+48-50
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,59 @@ export default angular.module('googleTranslate', [])
88
target: 'ru'
99
})
1010

11-
.factory('googleTranslateService', function ($http, $timeout, googleTranslateConfig) {
11+
.factory('googleTranslateService', function googleTranslateService($http, $timeout, googleTranslateConfig) {
1212
'ngInject';
13-
13+
1414
return {
15-
playAudio,
16-
getTranslation
17-
};
15+
/**
16+
* Play audio with word
17+
* @param {string} word Word for playing
18+
* @param {int} timeout Delay time
19+
*/
20+
playAudio(word, timeout = 0) {
21+
const audioUrl = `${googleTranslateConfig.domain}/translate_tts?client=gtx&tl=en&q=${decodeURI(word)}`;
22+
const audio = new Audio(audioUrl);
23+
$timeout(() => {
24+
audio.play();
25+
}, timeout);
26+
},
1827

19-
/**
20-
* Play audio with word
21-
* @param {string} word
22-
* @param {int} timeout
23-
*/
24-
function playAudio(word, timeout = 0) {
25-
let audio = new Audio(`${googleTranslateConfig.domain}/translate_tts?client=gtx&tl=en&q=${decodeURI(word)}`);
26-
$timeout(() => {
27-
audio.play();
28-
}, timeout);
29-
}
28+
/**
29+
* Returned translation by query
30+
* @param {string} query Word for translation
31+
* @returns {*|Promise.<TResult>} Promise
32+
*/
33+
getTranslation(query) {
34+
const promise = $http({
35+
method: 'GET',
36+
url: `${googleTranslateConfig.domain}/translate_a/single`,
37+
crossDomain: true,
38+
params: {
39+
client: 'gtx',
40+
sl: googleTranslateConfig.source,
41+
tl: googleTranslateConfig.target,
42+
dt: 't',
43+
q: query
44+
},
45+
transformResponse(res) {
46+
try {
47+
return JSON.parse(res.replace(/,(?=,)/g, ',null'));
48+
} catch (e) {
49+
return eval(res);
50+
}
51+
}
52+
});
3053

31-
/**
32-
* Returned translation by query
33-
* @param {string} query
34-
* @returns {*|Promise.<TResult>}
35-
*/
36-
function getTranslation(query) {
37-
let promise = $http({
38-
method: 'GET',
39-
url: `${googleTranslateConfig.domain}/translate_a/single`,
40-
crossDomain: true,
41-
params: {
42-
client: 'gtx',
43-
sl: googleTranslateConfig.source,
44-
tl: googleTranslateConfig.target,
45-
dt: 't',
46-
q: query
47-
},
48-
transformResponse: res => {
54+
return promise.then(res => {
55+
console.log(res);
56+
let result = null;
4957
try {
50-
return JSON.parse(res.replace(/,(?=,)/g, ',null'));
58+
result = res.data[0][0][0];
5159
} catch (e) {
52-
return eval(res);
60+
console.log('Can`t translate word');
5361
}
54-
}
55-
});
56-
57-
return promise.then(res => {
58-
console.log(res);
59-
let result = null;
60-
try {
61-
result = res.data[0][0][0];
62-
} catch (e) {
63-
console.log('Can`t translate word');
64-
}
65-
return result;
66-
});
67-
}
62+
return result;
63+
});
64+
}
65+
};
6866
});

src/app/common/notification/notification.service.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
import angular from 'angular';
33

44
export default angular.module('notification', [])
5-
.factory('notificationService', function () {
5+
.factory('notificationService', function notificationService() {
66
return {
7-
push
7+
/**
8+
* Show push notification
9+
* @param {string} title Notification title
10+
* @param {string} body Notification body
11+
* @returns {object} Notification object
12+
*/
13+
push(title, body) {
14+
return new Notification(title, {body: body});
15+
}
816
};
9-
10-
/**
11-
* Show push notification
12-
* @param {string} title
13-
* @param {string} body
14-
*/
15-
function push(title, body) {
16-
return new Notification(title, {body: body});
17-
}
1817
});
1918

0 commit comments

Comments
 (0)