-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadderess-finder.js
136 lines (99 loc) · 3.46 KB
/
adderess-finder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import Address from './address.js';
import {filter, map, some, find, isObject, cloneDeep} from 'lodash';
import formatter from './formatter.js';
class AddressFinder {
constructor () {
this.currentAddress = new Address();
this.lastAddresses = [];
}
isFull () {
if (this.currentAddress && this.currentAddress.address && this.currentAddress.address.point) {
return true;
}
return false;
}
isEmpty () {
if (this.currentAddress && !this.currentAddress.address) {
return true;
}
}
getAddressObjectList (pattern) {
var self = this;
return new Promise(function (resolve, reject) {
var currentAddress = self.currentAddress;
if (currentAddress && currentAddress.address) {
let parentId;
if (Address.hasLocality(currentAddress.address)){
parentId = Address.getLocality(currentAddress.address).id;
}
if (Address.hasStreet(currentAddress.address)){
parentId = Address.getStreet(currentAddress.address).id;
}
Address.getPoints(parentId, pattern).then((resp) => {
resolve(resp);
});
}
else {
Address.getAddress(pattern).then((resp) => {
resolve(resp);
});
}
})
}
formatterCurrentToArray () {
return formatter.formatToArray(this.currentAddress.address);
}
formatterCurrentToString() {
return formatter.format(this.currentAddress.address);
}
//форматируем в массив из двух элементов - адрес и алиас
formatterCurrentToSplit() {
return formatter.formatToSplit(this.currentAddress.address);
}
setCurrentAddress (addressObj) {
if (this.currentAddress.address) {
var currentAddress = cloneDeep(this.currentAddress.address);
this.lastAddresses.push(currentAddress);
}
this.currentAddress.setAddress(addressObj);
}
setPorchToCurrrent (porch){
if (this.isFull()){
this.currentAddress.address.point.porch = porch
}
}
setFlatToCurrrent (flat){
if (this.isFull()){
this.currentAddress.address.point.flat = flat
}
}
setPreviousAddress () {
var lastLength = this.lastAddresses.length;
if (lastLength){
var prevAddress = this.lastAddresses.pop();
this.currentAddress.setAddress(prevAddress);
} else {
this.currentAddress.clear();
}
}
formatter (addressObj, type) {
var str = '';
// форматирование в списке
if (type === 'list') {
//если есть установленаня улица или еще что-то
if (isObject(this.currentAddress.address)) {
if (Address.isPoint(addressObj)){
str = str + formatter.formatPoint(addressObj, this.currentAddress.address)
} else {
str = str + formatter.format(addressObj);
}
}
// если это первичный поиск
else {
str = str + formatter.format(addressObj);
}
}
return str;
}
}
export default AddressFinder;