Files
flights_web_raw/apps/angular/node_modules/.cache/babel-webpack/5561cdc64243b5fb71fe47f13d6c5411.json
T

1 line
27 KiB
JSON

{"ast":null,"code":"import _asyncToGenerator from \"/Users/gnezim/_projects/tims/flights_web_raw/Aeroflot.Flights.Web/apps/angular/node_modules/@babel/runtime/helpers/esm/asyncToGenerator\";\nimport * as i0 from \"@angular/core\";\nimport * as i1 from \"@shared/services/localization.service\";\nimport * as i2 from \"@shared/services/network.service\";\nimport * as i3 from \"@app/shared/services\";\nexport class DictionariesService {\n constructor(localizationService, networkService, geo) {\n this.networkService = networkService;\n this.geo = geo;\n this.regions = [];\n this.ruCitiesCodes = new Set();\n this.otherCitiesCodes = new Set();\n this.russiaRegionId = 500374;\n this.lang = localizationService.Language;\n this.ready$ = this.load().then(() => {\n this.filterAustralia();\n });\n }\n\n locate() {\n var _this = this;\n\n return _asyncToGenerator(function* () {\n try {\n const position = yield _this.geo.getPosition();\n return _this.findCityByCoord(position.latitude, position.longitude);\n } catch (e) {\n return undefined;\n }\n })();\n }\n\n findCityByCoord(lat, lon) {\n var _a;\n\n if (!this.citiesAll) {\n return;\n }\n\n let res = this.citiesAll.map(city => {\n if (city.location) {\n const dist = this.calcCrow(lat, lon, city.location.lat, city.location.lon);\n return {\n dist,\n city\n };\n }\n });\n res = res.sort((a, b) => {\n if (a.dist < b.dist) return -1;else return 1;\n });\n return (_a = res[0]) === null || _a === void 0 ? void 0 : _a.city;\n }\n\n calcCrow(lat1, lon1, lat2, lon2) {\n const R = 6371; // km\n\n const dLat = this.toRad(lat2 - lat1);\n const dLon = this.toRad(lon2 - lon1);\n lat1 = this.toRad(lat1);\n lat2 = this.toRad(lat2);\n const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);\n const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n const d = R * c;\n return d;\n }\n\n toRad(Value) {\n return Value * Math.PI / 180;\n }\n\n getCityOrAirport(code) {\n var _a, _b, _c;\n\n return (_b = (_a = this.citiesCodeMap) === null || _a === void 0 ? void 0 : _a.get(code)) !== null && _b !== void 0 ? _b : (_c = this.airportsCodeMap) === null || _c === void 0 ? void 0 : _c.get(code);\n }\n\n getCityByCode(code) {\n var _a;\n\n return (_a = this.citiesCodeMap) === null || _a === void 0 ? void 0 : _a.get(code.toUpperCase());\n }\n\n getCityCodeByAirportCode(code) {\n var _a;\n\n return (_a = this.airportsCodeMap) === null || _a === void 0 ? void 0 : _a.get(code.toUpperCase()).city_code;\n }\n\n getAirportByCode(code) {\n var _a;\n\n return (_a = this.airportsCodeMap) === null || _a === void 0 ? void 0 : _a.get(code.toUpperCase());\n }\n\n getCityOrAirportNameAsync(code) {\n return this.ready$.then(() => {\n var _a;\n\n return ((_a = this.getCityOrAirport(code)) === null || _a === void 0 ? void 0 : _a.name) || '';\n });\n }\n\n filterAustralia() {\n // hide australia tab https://wzcloud.visualstudio.com/Aeroflot%202/_workitems/edit/8095\n const australiaRegionId = 500373;\n this.regions = this.regions.filter(region => {\n return region.id !== australiaRegionId;\n });\n this.regionsAll = this.regionsAll.filter(region => {\n return region.world_region_id !== australiaRegionId;\n });\n }\n\n handleLoading(regions, countries, cities, airports) {\n this.regions = [];\n this.regionsAll = this.sortRegions(regions);\n this.countriesAll = countries;\n this.citiesAll = cities.filter(x => !/^[a-zA-Z.,:; ]+$/.test(x.title['ru']));\n this.citiesAll.forEach(city => {\n if (city.country_code === \"RU\") {\n this.ruCitiesCodes.add(city.code);\n } else {\n this.otherCitiesCodes.add(city.code);\n }\n });\n this.citiesCodeMap = new Map(this.citiesAll.map(c => [c.code, c]));\n this.airportsAll = airports.filter(x => x.has_afl_flights == true && !/^[a-zA-Z.,:; ]+$/.test(x.title['ru'].toLowerCase()));\n this.airportsCodeMap = new Map(this.airportsAll.map(a => [a.code, a]));\n\n for (const city of this.citiesAll) {\n city.name = city.title[this.lang];\n const airports = this.airportsAll.filter(x => x.city_code == city.code);\n city.has_afl_flights = airports.length > 0;\n city.airports = this.sortByTitle(airports);\n city.airports.forEach(airport => {\n airport.name = airport.title[this.lang];\n });\n const country = this.countriesAll.find(x => x.code == city.country_code);\n\n if (country) {\n city.countryName = country.title[this.lang];\n }\n }\n\n this.citiesAll = this.citiesAll.filter(x => x.has_afl_flights);\n\n for (const region of regions) {\n const r = {\n id: region.world_region_id,\n name: region.title[this.lang],\n countries: []\n };\n this.regions.push(r); //_contries.push(contres.find(x=>x.code===\"RU\"));\n\n const _countries = countries.filter(x => x.world_region_id == region.world_region_id && x.code != 'RU').sort((a, b) => a.title[this.lang] > b.title[this.lang] ? 1 : -1);\n\n if (r.id == this.russiaRegionId) {\n _countries.splice(0, 0, countries.find(x => x.code == 'RU'));\n }\n\n for (const country of _countries) {\n const citiesFiltred = this.citiesAll.filter(x => x.country_code == country.code && x.code != 'MOW').sort((a, b) => a.title[this.lang] > b.title[this.lang] ? 1 : -1);\n const mowCity = this.citiesAll.find(x => x.code == 'MOW');\n\n if (country.code == 'RU' && typeof mowCity !== 'undefined') {\n citiesFiltred.splice(0, 0, mowCity);\n }\n\n for (let i = 0; i < citiesFiltred.length; i++) {\n const countryModel = {\n code: country.code\n };\n r.countries.push(countryModel);\n\n if (i == 0) {\n countryModel.name = country.title[this.lang];\n }\n\n countryModel.city1 = citiesFiltred[i];\n countryModel.city1.name = citiesFiltred[i].title[this.lang];\n\n if (citiesFiltred[i].airports.length > 1) {\n continue;\n }\n\n i++;\n if (i >= citiesFiltred.length) break;\n countryModel.city2 = citiesFiltred[i];\n countryModel.city2.name = citiesFiltred[i].title[this.lang];\n }\n }\n }\n } // ToDo: refactor\n\n\n load() {\n return Promise.all([this.networkService.getDictionary('world_regions'), this.networkService.getDictionary('countries'), this.networkService.getDictionary('cities'), this.networkService.getDictionary('airports')]).then(res => this.handleLoading(res[0], res[1], res[2], res[3])); // Performance optimization; saves 100ms\n }\n /**\n * Per requirements, regions should be sorted by name but Russia should always be first region\n */\n\n\n sortRegions(regions) {\n const sortedRegions = this.sortByTitle(regions);\n const ru = sortedRegions.splice(sortedRegions.findIndex(r => r.world_region_id == this.russiaRegionId), 1);\n sortedRegions.unshift(...ru);\n return sortedRegions;\n }\n\n sortByTitle(data) {\n return data.sort((a, b) => a.title[this.lang].toLowerCase().localeCompare(b.title[this.lang].toLowerCase()));\n }\n\n}\n\nDictionariesService.ɵfac = function DictionariesService_Factory(t) {\n return new (t || DictionariesService)(i0.ɵɵinject(i1.LocalizationService), i0.ɵɵinject(i2.NetworkService), i0.ɵɵinject(i3.GeoService));\n};\n\nDictionariesService.ɵprov = /*@__PURE__*/i0.ɵɵdefineInjectable({\n token: DictionariesService,\n factory: DictionariesService.ɵfac,\n providedIn: 'root'\n});","map":{"version":3,"sources":["/Users/gnezim/_projects/tims/flights_web_raw/Aeroflot.Flights.Web/apps/angular/src/app/modules/components/page-filters/services/dictionaries-service.ts"],"names":["i0","i1","i2","i3","DictionariesService","constructor","localizationService","networkService","geo","regions","ruCitiesCodes","Set","otherCitiesCodes","russiaRegionId","lang","Language","ready$","load","then","filterAustralia","locate","position","getPosition","findCityByCoord","latitude","longitude","e","undefined","lat","lon","_a","citiesAll","res","map","city","location","dist","calcCrow","sort","a","b","lat1","lon1","lat2","lon2","R","dLat","toRad","dLon","Math","sin","cos","c","atan2","sqrt","d","Value","PI","getCityOrAirport","code","_b","_c","citiesCodeMap","get","airportsCodeMap","getCityByCode","toUpperCase","getCityCodeByAirportCode","city_code","getAirportByCode","getCityOrAirportNameAsync","name","australiaRegionId","filter","region","id","regionsAll","world_region_id","handleLoading","countries","cities","airports","sortRegions","countriesAll","x","test","title","forEach","country_code","add","Map","airportsAll","has_afl_flights","toLowerCase","length","sortByTitle","airport","country","find","countryName","r","push","_countries","splice","citiesFiltred","mowCity","i","countryModel","city1","city2","Promise","all","getDictionary","sortedRegions","ru","findIndex","unshift","data","localeCompare","ɵfac","DictionariesService_Factory","t","ɵɵinject","LocalizationService","NetworkService","GeoService","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AAA,UAAU,EAAE;AAA7E,CAAtB,CAA1C","sourcesContent":["import * as i0 from \"@angular/core\";\nimport * as i1 from \"@shared/services/localization.service\";\nimport * as i2 from \"@shared/services/network.service\";\nimport * as i3 from \"@app/shared/services\";\nexport class DictionariesService {\n constructor(localizationService, networkService, geo) {\n this.networkService = networkService;\n this.geo = geo;\n this.regions = [];\n this.ruCitiesCodes = new Set();\n this.otherCitiesCodes = new Set();\n this.russiaRegionId = 500374;\n this.lang = localizationService.Language;\n this.ready$ = this.load().then(() => {\n this.filterAustralia();\n });\n }\n async locate() {\n try {\n const position = await this.geo.getPosition();\n return this.findCityByCoord(position.latitude, position.longitude);\n }\n catch (e) {\n return undefined;\n }\n }\n findCityByCoord(lat, lon) {\n var _a;\n if (!this.citiesAll) {\n return;\n }\n let res = this.citiesAll.map((city) => {\n if (city.location) {\n const dist = this.calcCrow(lat, lon, city.location.lat, city.location.lon);\n return { dist, city };\n }\n });\n res = res.sort((a, b) => {\n if (a.dist < b.dist)\n return -1;\n else\n return 1;\n });\n return (_a = res[0]) === null || _a === void 0 ? void 0 : _a.city;\n }\n calcCrow(lat1, lon1, lat2, lon2) {\n const R = 6371; // km\n const dLat = this.toRad(lat2 - lat1);\n const dLon = this.toRad(lon2 - lon1);\n lat1 = this.toRad(lat1);\n lat2 = this.toRad(lat2);\n const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +\n Math.sin(dLon / 2) *\n Math.sin(dLon / 2) *\n Math.cos(lat1) *\n Math.cos(lat2);\n const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n const d = R * c;\n return d;\n }\n toRad(Value) {\n return (Value * Math.PI) / 180;\n }\n getCityOrAirport(code) {\n var _a, _b, _c;\n return (_b = (_a = this.citiesCodeMap) === null || _a === void 0 ? void 0 : _a.get(code)) !== null && _b !== void 0 ? _b : (_c = this.airportsCodeMap) === null || _c === void 0 ? void 0 : _c.get(code);\n }\n getCityByCode(code) {\n var _a;\n return (_a = this.citiesCodeMap) === null || _a === void 0 ? void 0 : _a.get(code.toUpperCase());\n }\n getCityCodeByAirportCode(code) {\n var _a;\n return (_a = this.airportsCodeMap) === null || _a === void 0 ? void 0 : _a.get(code.toUpperCase()).city_code;\n }\n getAirportByCode(code) {\n var _a;\n return (_a = this.airportsCodeMap) === null || _a === void 0 ? void 0 : _a.get(code.toUpperCase());\n }\n getCityOrAirportNameAsync(code) {\n return this.ready$.then(() => {\n var _a;\n return ((_a = this.getCityOrAirport(code)) === null || _a === void 0 ? void 0 : _a.name) || '';\n });\n }\n filterAustralia() {\n // hide australia tab https://wzcloud.visualstudio.com/Aeroflot%202/_workitems/edit/8095\n const australiaRegionId = 500373;\n this.regions = this.regions.filter((region) => {\n return region.id !== australiaRegionId;\n });\n this.regionsAll = this.regionsAll.filter((region) => {\n return region.world_region_id !== australiaRegionId;\n });\n }\n handleLoading(regions, countries, cities, airports) {\n this.regions = [];\n this.regionsAll = this.sortRegions(regions);\n this.countriesAll = countries;\n this.citiesAll = cities.filter((x) => !/^[a-zA-Z.,:; ]+$/.test(x.title['ru']));\n this.citiesAll.forEach(city => {\n if (city.country_code === \"RU\") {\n this.ruCitiesCodes.add(city.code);\n }\n else {\n this.otherCitiesCodes.add(city.code);\n }\n });\n this.citiesCodeMap = new Map(this.citiesAll.map((c) => [c.code, c]));\n this.airportsAll = airports.filter((x) => x.has_afl_flights == true &&\n !/^[a-zA-Z.,:; ]+$/.test(x.title['ru'].toLowerCase()));\n this.airportsCodeMap = new Map(this.airportsAll.map((a) => [a.code, a]));\n for (const city of this.citiesAll) {\n city.name = city.title[this.lang];\n const airports = this.airportsAll.filter((x) => x.city_code == city.code);\n city.has_afl_flights = airports.length > 0;\n city.airports = this.sortByTitle(airports);\n city.airports.forEach((airport) => {\n airport.name = airport.title[this.lang];\n });\n const country = this.countriesAll.find((x) => x.code == city.country_code);\n if (country) {\n city.countryName = country.title[this.lang];\n }\n }\n this.citiesAll = this.citiesAll.filter((x) => x.has_afl_flights);\n for (const region of regions) {\n const r = {\n id: region.world_region_id,\n name: region.title[this.lang],\n countries: [],\n };\n this.regions.push(r);\n //_contries.push(contres.find(x=>x.code===\"RU\"));\n const _countries = countries\n .filter((x) => x.world_region_id == region.world_region_id &&\n x.code != 'RU')\n .sort((a, b) => a.title[this.lang] > b.title[this.lang] ? 1 : -1);\n if (r.id == this.russiaRegionId) {\n _countries.splice(0, 0, countries.find((x) => x.code == 'RU'));\n }\n for (const country of _countries) {\n const citiesFiltred = this.citiesAll\n .filter((x) => x.country_code == country.code && x.code != 'MOW')\n .sort((a, b) => a.title[this.lang] > b.title[this.lang] ? 1 : -1);\n const mowCity = this.citiesAll.find((x) => x.code == 'MOW');\n if (country.code == 'RU' && typeof mowCity !== 'undefined') {\n citiesFiltred.splice(0, 0, mowCity);\n }\n for (let i = 0; i < citiesFiltred.length; i++) {\n const countryModel = {\n code: country.code,\n };\n r.countries.push(countryModel);\n if (i == 0) {\n countryModel.name = country.title[this.lang];\n }\n countryModel.city1 = citiesFiltred[i];\n countryModel.city1.name = citiesFiltred[i].title[this.lang];\n if (citiesFiltred[i].airports.length > 1) {\n continue;\n }\n i++;\n if (i >= citiesFiltred.length)\n break;\n countryModel.city2 = citiesFiltred[i];\n countryModel.city2.name = citiesFiltred[i].title[this.lang];\n }\n }\n }\n }\n // ToDo: refactor\n load() {\n return Promise.all([\n this.networkService.getDictionary('world_regions'),\n this.networkService.getDictionary('countries'),\n this.networkService.getDictionary('cities'),\n this.networkService.getDictionary('airports'),\n ]).then((res) => this.handleLoading(res[0], res[1], res[2], res[3])); // Performance optimization; saves 100ms\n }\n /**\n * Per requirements, regions should be sorted by name but Russia should always be first region\n */\n sortRegions(regions) {\n const sortedRegions = this.sortByTitle(regions);\n const ru = sortedRegions.splice(sortedRegions.findIndex((r) => r.world_region_id == this.russiaRegionId), 1);\n sortedRegions.unshift(...ru);\n return sortedRegions;\n }\n sortByTitle(data) {\n return data.sort((a, b) => a.title[this.lang]\n .toLowerCase()\n .localeCompare(b.title[this.lang].toLowerCase()));\n }\n}\nDictionariesService.ɵfac = function DictionariesService_Factory(t) { return new (t || DictionariesService)(i0.ɵɵinject(i1.LocalizationService), i0.ɵɵinject(i2.NetworkService), i0.ɵɵinject(i3.GeoService)); };\nDictionariesService.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: DictionariesService, factory: DictionariesService.ɵfac, providedIn: 'root' });\n"]},"metadata":{},"sourceType":"module"}