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

Commit

Permalink
Merge pull request #444 from datagovsg/lint-directives
Browse files Browse the repository at this point in the history
Linter auto-fix everything
  • Loading branch information
joelchoo authored Nov 24, 2017
2 parents e98d745 + b46a269 commit f50b26c
Show file tree
Hide file tree
Showing 77 changed files with 2,403 additions and 2,438 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"parser": "babel-eslint",
"extends": [
"eslint:recommended",
"google",
"plugin:angular/johnpapa"
"google"
],
"env": {
"browser": true,
Expand Down
86 changes: 43 additions & 43 deletions beeline/SafeInterval.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import assert from 'assert';

export class SafeInterval {
constructor(fn, interval, retryTimeout) {
this.isRunning = false;
this.timeout = null;

retryTimeout = retryTimeout || interval;

//fn returns a Promise
this.loop = function() {
this.timeout = null;

var promise = this.currentPromise = fn();

this.currentPromise
.then(()=>{
if (promise == this.currentPromise && this.isRunning) {
this.timeout = setTimeout(this.loop, interval);
}
})
.catch((err) => {
console.log(err)
if (promise == this.currentPromise && this.isRunning) {
this.timeout = setTimeout(this.loop, retryTimeout);
}
})
}.bind(this);
}

stop() {
this.isRunning = false;
if (this.timeout !== null) {
clearTimeout(this.timeout);
}
}

start() {
if (this.isRunning) return;
this.isRunning = true;
this.loop();
}
}
import assert from 'assert'

export class SafeInterval {
constructor (fn, interval, retryTimeout) {
this.isRunning = false
this.timeout = null

retryTimeout = retryTimeout || interval

// fn returns a Promise
this.loop = function () {
this.timeout = null

let promise = this.currentPromise = fn()

this.currentPromise
.then(()=>{
if (promise == this.currentPromise && this.isRunning) {
this.timeout = setTimeout(this.loop, interval)
}
})
.catch((err) => {
console.log(err)
if (promise == this.currentPromise && this.isRunning) {
this.timeout = setTimeout(this.loop, retryTimeout)
}
})
}.bind(this)
}

stop () {
this.isRunning = false
if (this.timeout !== null) {
clearTimeout(this.timeout)
}
}

start () {
if (this.isRunning) return
this.isRunning = true
this.loop()
}
}
80 changes: 40 additions & 40 deletions beeline/SafeScheduler.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import assert from 'assert';

export class SafeScheduler {
constructor(fn, hours, minutes = 0, seconds = 0) {
this.isRunning = false;
this.timeout = null;

//fn returns a Promise
this.loop = function() {
this.timeout = null;

fn()
.then(()=>{
if (this.isRunning) {
this.timeout = setTimeout(this.loop,
new Date().setHours(hours, minutes, seconds) - Date.now()
);
}
})
.catch(() => {
if (this.isRunning) {
this.timeout = setTimeout(this.loop, 60000 /* retryTimeout */);
}
})
}.bind(this);
}

stop() {
this.isRunning = false;
if (this.timeout !== null) {
clearTimeout(this.timeout);
}
}

start() {
assert (!this.isRunning);
this.isRunning = true;
this.loop();
}
}
import assert from 'assert'

export class SafeScheduler {
constructor (fn, hours, minutes = 0, seconds = 0) {
this.isRunning = false
this.timeout = null

// fn returns a Promise
this.loop = function () {
this.timeout = null

fn()
.then(()=>{
if (this.isRunning) {
this.timeout = setTimeout(this.loop,
new Date().setHours(hours, minutes, seconds) - Date.now()
)
}
})
.catch(() => {
if (this.isRunning) {
this.timeout = setTimeout(this.loop, 60000 /* retryTimeout */)
}
})
}.bind(this)
}

stop () {
this.isRunning = false
if (this.timeout !== null) {
clearTimeout(this.timeout)
}
}

start () {
assert(!this.isRunning)
this.isRunning = true
this.loop()
}
}
78 changes: 39 additions & 39 deletions beeline/directives/autocomplete.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
export default ['uiGmapGoogleMapApi',
function(uiGmapGoogleMapApi) {
function (uiGmapGoogleMapApi) {
return {
scope: true,
link(scope, element, attribute) {
link (scope, element, attribute) {
uiGmapGoogleMapApi.then((googleMaps) => {

// Initialize it with google autocomplete
scope.autocomplete = new googleMaps.places.Autocomplete(element[0], {
componentRestrictions: {country: 'SG'}
});
scope.autocompleteService = new googleMaps.places.AutocompleteService();
scope.placesService = new google.maps.places.PlacesService(element[0]);
componentRestrictions: {country: 'SG'},
})
scope.autocompleteService = new googleMaps.places.AutocompleteService()
scope.placesService = new google.maps.places.PlacesService(element[0])

// Bind the place change property as a listener
// If a proper autocomplete option is selected then just callback
// Otherwise make a best effort attempt to find one with the free text
scope.autocomplete.addListener('place_changed', () => {
let place = scope.autocomplete.getPlace();
let place = scope.autocomplete.getPlace()
// Augment the object with the autocomplete string
place.description = element[0].value;
place.description = element[0].value
// Also set it as the query text paramter for consistency with the
// "free text" scenario
place.queryText = place.description;
place.queryText = place.description
// If a proper autocomplete option is selected then just callback
// Also do so if theres nothing to autocomplete
if (place.geometry || place.name.length === 0) {
scope.$apply(() => {
scope.$eval(attribute['placeChanged'], { '$event': place });
});
scope.$eval(attribute['placeChanged'], {'$event': place})
})
}
// If free text is entered then try to complete it
// "free text" is an object with just a name attribute specified
Expand All @@ -36,55 +35,56 @@ export default ['uiGmapGoogleMapApi',
// Start by manually calling the autocomplete service
scope.autocompleteService.getPlacePredictions({
componentRestrictions: {country: 'SG'},
input: place.name
input: place.name,
}, (predictions) => {
// If no results found then just shortcircuit with the empty place
if (!predictions || predictions.length === 0) {
scope.$apply(() => {
scope.$eval(attribute['placeChanged'], { '$event': place });
});
return;
scope.$eval(attribute['placeChanged'], {'$event': place})
})
return
}
// Grab the top prediction and get the details
// Apply the details as the full result
scope.placesService.getDetails({
placeId: predictions[0].place_id
}, result => {
placeId: predictions[0].place_id,
}, (result) => {
// If we fail getting the details then shortcircuit
if (!result) {
scope.$apply(() => {
scope.$eval(attribute['placeChanged'], { '$event': place });
});
return;
scope.$eval(attribute['placeChanged'], {'$event': place})
})
return
}
// Otherwise return the fully formed place
place = result;
place = result
// Augment the object with the prediction string
place.description = predictions[0].description;
place.description = predictions[0].description
// Augment the query result with the original query text
place.queryText = element[0].value;
place.queryText = element[0].value
// Return the found place
scope.$apply(() => {
scope.$eval(attribute['placeChanged'], { '$event': place });
});
});
});
scope.$eval(attribute['placeChanged'], {'$event': place})
})
})
})
}
});
})

// Blur on enter
element[0].addEventListener("keypress", function(event) {
if (event.key === "Enter") this.blur();
});
element[0].addEventListener('keypress', function (event) {
if (event.key === 'Enter') this.blur()
})

// Hack to get ionic fast tap working nicely with google maps
// see http://ionicframework.com/docs/v1/api/page/tap/
element[0].addEventListener("focus", function(event) {
const pacContainers = document.querySelectorAll('.pac-container');
for (let pac of pacContainers) { pac.dataset.tapDisabled = true; }
});

});
}
element[0].addEventListener('focus', function (event) {
const pacContainers = document.querySelectorAll('.pac-container')
for (let pac of pacContainers) {
pac.dataset.tapDisabled = true
}
})
})
},
}
}]
21 changes: 10 additions & 11 deletions beeline/directives/beelineBindHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@ export default ['$compile', function ($compile) {
return {
restrict: 'A',
scope: false,
link(scope, elem, attrs) {
link (scope, elem, attrs) {
scope.$watch(attrs.beelineBindHtml, (html) => {
elem[0].innerHTML = html || '';
elem[0].innerHTML = html || ''

scope.$openOpenLink = (href) => {
if (typeof cordova !== 'undefined') {
cordova.InAppBrowser.open(href, '_system');
cordova.InAppBrowser.open(href, '_system')
} else {
window.open(href, '_blank')
}
else {
window.open(href, '_blank');
}
};
}

angular.forEach(elem.find('a'), (value, key) => {
if (!value.href) return;
if (!value.href) return

value.setAttribute("ng-click", `$openOpenLink(${JSON.stringify(value.href)})`)
value.setAttribute('ng-click', `$openOpenLink(${JSON.stringify(value.href)})`)

$compile(value)(scope);
$compile(value)(scope)
})
})
}
},
}
}]
11 changes: 5 additions & 6 deletions beeline/directives/bookingBreadcrumbs/bookingBreadcrumbs.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@


export default ['$rootScope',
function breadcrumbs($rootScope) {
function breadcrumbs ($rootScope) {
return {
template:
`<div class="item"><img ng-src="{{breadcrumbs_dir}}{{imgNames[step]}}"></div>`,
scope: {
step: '@',
},
link: function(scope, elem, attr) {
link: function (scope, elem, attr) {
scope.breadcrumbs_dir = 'img/'+$rootScope.o.APP.PREFIX + 'booking-breadcrumbs/'
scope.imgNames = [
'ProgressBar01_ChooseStops.svg',
'ProgressBar02_ChooseDates.svg',
'ProgressBar03_ReviewBooking.svg',
'ProgressBar04_MakePayment.svg',
];

}
};
]
},
}
}]
Loading

0 comments on commit f50b26c

Please sign in to comment.