Skip to content
This repository has been archived by the owner on May 11, 2020. It is now read-only.

Commit

Permalink
Add basic multi-sim and no-sim support
Browse files Browse the repository at this point in the history
Changes include
* change format of countries.json & modify other files accordingly
* ask user for mcc/mnc if unknown
* ask user to select sim-card if he has multiple sim-cars

The new format seems more appropriate & flexible, an example being the usage of mccs as keys in the old format (mccs are not guaranteed to be unique per country)
The new format is:
[{"code": iso, "full": fullname, "prefix": +pre, "carriers": {carrier_name: [{"mcc": mcc, "mnc": mnc}, ..], ...}}, ...]
A tool to create this file from a csv-list is added to /tools/create_countries_json.py, and the other files have been changed accordingly.

The user is asked for mcc/mnc if
1. He does not have a sim-card inserted or
2. The selected (or only) sim-card is not associated with the selected country
  • Loading branch information
duesenfranz committed Dec 8, 2014
1 parent 9f9567c commit 4d4380b
Show file tree
Hide file tree
Showing 7 changed files with 10,861 additions and 1,222 deletions.
26 changes: 12 additions & 14 deletions app/scripts/collections/countries.js
Expand Up @@ -20,13 +20,14 @@ define([
fetchCountries: function () {
// Get from the countries.json. responseType to json is not allowed, see
// http://updates.html5rocks.com/2012/01/Getting-Rid-of-Synchronous-XHRs
var xhr = new XMLHttpRequest();
var xhr = new XMLHttpRequest(),
_this = this;
xhr.open('GET', '/scripts/countries.json', false); // sync request
xhr.send(null);

//Fill with an empty country
this.add(new Country({
mcc: 0,
networkList: {},
code: '',
name: global.localisation[global.language].country,
prefix: ''
Expand All @@ -40,15 +41,12 @@ define([
console.error('Something happened while trying to parse the JSON', e);
}

// And walk over all countries found
var keys = _.keys(parsed);
var _this = this;
keys.forEach(function (key) {
parsed.map(function(country) {
_this.add(new Country({
mcc: parseInt(key, 10),
code: parsed[key].code,
name: parsed[key].full,
prefix: parsed[key].prefix
carriers: country.carriers,
code: country.code,
name: country.full,
prefix: country.prefix
}));
});
} else {
Expand All @@ -63,11 +61,11 @@ define([
return result;
},

getCountryByMCC: function (mcc) {
var result = this.find(function (model) {
return model.get('mcc') === mcc;
getCountryByMccMnc: function (mcc, mnc) {
//TODO: slow! maybe make a hashmap of concentated mcc and mnc
return this.find(function (model) {
return model.hasMccMnc(mcc, mnc);
});
return result;
}
});

Expand Down

0 comments on commit 4d4380b

Please sign in to comment.