Skip to content

Commit

Permalink
feat(core): add support for Ionic Deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Reed committed Jul 8, 2015
1 parent f246462 commit e8a1675
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 26 deletions.
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
},
"devDependencies": {
"angular-mocks": "1.3.16",
"ionic": "1.0.1"
"ionic": "1.0.1",
"ionic-service-deploy": "*"
},
"resolutions": {
"angular": "1.3.16",
Expand Down
3 changes: 2 additions & 1 deletion build-properties.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"admobIdAndroidBanner": undefined,
"admobIdAndroidInterstitial": undefined,
"admobIdOtherBanner": undefined,
"admobIdOtherInterstitial": undefined
"admobIdOtherInterstitial": undefined,
"ionicPublicKey": undefined,
}
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var paths = {
src: './src/**/*',
sass: './scss/*.scss',
sassIncludes: './scss/includes/*.scss',
opennms: './www/scripts/opennms/**/*.js',
opennms: './src/scripts/opennms/**/*.js',
spec: './spec/*.js',
excludes: [],
};
Expand Down
4 changes: 2 additions & 2 deletions hooks/before_prepare/generate_build_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ if (rootdir) {
}
var value = buildobj[prop];
if (typeof value == 'string' || value instanceof String) {
fs.appendFileSync(outfile, "\t\t.value('config.build." + prop + "', '" + value + "')\n");
fs.appendFileSync(outfile, "\t\t.constant('config.build." + prop + "', '" + value + "')\n");
} else {
fs.appendFileSync(outfile, "\t\t.value('config.build." + prop + "', " + value + ")\n");
fs.appendFileSync(outfile, "\t\t.constant('config.build." + prop + "', " + value + ")\n");
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@
"cordovaPlugins": [
"com.ionic.keyboard",
"cordova-plugin-extension",
"cordova-plugin-admobpro",
"cordova-plugin-appavailability",
"cordova-plugin-console",
"cordova-plugin-datepicker",
"cordova-plugin-geolocation",
"https://github.com/RangerRick/google-analytics-plugin",
"cordova-plugin-inappbrowser",
"cordova-plugin-network-information",
"cordova-plugin-purchase",
"cordova-plugin-splashscreen",
"cordova-plugin-statusbar",
"cordova-plugin-whitelist",
Expand All @@ -75,8 +77,10 @@
"locator": "https://github.com/apache/cordova-plugin-file",
"id": "org.apache.cordova.file"
},
"cordova-plugin-admobpro",
"cordova-plugin-purchase"
{
"locator": "https://github.com/driftyco/ionic-plugins-deploy",
"id": "com.ionic.deploy"
}
],
"cordovaPlatforms": [
{
Expand Down
5 changes: 4 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!--<![endif]-->
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width" />
<meta name="format-detection" content="telephone=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src * 'self' 'unsafe-inline' 'unsafe-eval'">
Expand Down Expand Up @@ -68,6 +68,8 @@
<script src="lib/angular-ui-router/release/angular-ui-router.js"></script>
<script src="lib/ionic/release/js/ionic.js"></script>
<script src="lib/ionic/release/js/ionic-angular.js"></script>
<script src="lib/ionic-service-core/ionic-core.js"></script>
<script src="lib/ionic-service-deploy/ionic-deploy.js"></script>
<script src="lib/angular-debounce/dist/angular-debounce.js"></script>
<script src="lib/angularLocalStorage/src/angularLocalStorage.js"></script>
<script src="lib/ng-resize/ngresize.js"></script>
Expand Down Expand Up @@ -130,6 +132,7 @@
<script src="scripts/opennms/services/Events.js"></script>
<script src="scripts/opennms/services/IAP.js"></script>
<script src="scripts/opennms/services/Info.js"></script>
<script src="scripts/opennms/services/Ionic.js"></script>
<script src="scripts/opennms/services/Modals.js"></script>
<script src="scripts/opennms/services/Nodes.js"></script>
<script src="scripts/opennms/services/Outages.js"></script>
Expand Down
46 changes: 39 additions & 7 deletions src/scripts/opennms/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'opennms.services.Alarms',
'opennms.services.IAP',
'opennms.services.Info',
'opennms.services.Ionic',
'opennms.services.Modals',
'opennms.services.Outages',
'opennms.services.Settings',
Expand All @@ -29,6 +30,18 @@
.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider, $cordovaInAppBrowserProvider) {
$urlRouterProvider.otherwise('/dashboard');

$cordovaInAppBrowserProvider.setDefaultOptions({
location:'no',
enableViewportScale:'yes',
transitionstyle:'fliphorizontal',
toolbarposition:'top'
});

$ionicConfigProvider.views.maxCache(20);
$ionicConfigProvider.views.forwardCache(true);
$ionicConfigProvider.views.swipeBackEnabled(false);
$ionicConfigProvider.tabs.position('bottom');

$stateProvider
.state('dashboard', {
url: '/dashboard',
Expand Down Expand Up @@ -75,7 +88,7 @@
toolbarposition:'top'
});
})
.run(function($rootScope, $timeout, $window, $ionicPlatform, Ads, IAP, Info, Modals, Settings, util) {
.run(function($rootScope, $timeout, $window, $ionicPlatform, $ionicPopup, Ads, IAP, Info, IonicService, Modals, Settings, util) {
var updateTheme = function(info) {
if (!info) {
info = Info.get();
Expand All @@ -90,14 +103,33 @@

util.onInfoUpdated(updateTheme);

$ionicPlatform.ready(function() {
var init = function() {
console.log('Ionic is ready.');
IAP.init().then(Ads.init);
Settings.isServerConfigured().then(function(isConfigured) {
if (!isConfigured) {
Modals.settings();
}
});
};

IonicService.promptForUpdates().then(function(res) {
if (res) {
IonicService.update().then(function() {
var args = Array.prototype.slice.call(arguments);
console.log('Update complete: ' + angular.toJson(args));
}, function(err) {
$ionicPopup.alert({
title: 'Update failed.',
template: angular.toJson(err),
okType: 'button-compass',
});
init();
});
} else {
init();
}
});

Settings.isServerConfigured().then(function(isConfigured) {
if (!isConfigured) {
Modals.settings();
}
});
});
}());
23 changes: 12 additions & 11 deletions src/scripts/opennms/services/BuildConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
'use strict';

angular.module('opennms.services.BuildConfig', [])
.value('config.build.version', 'Unknown')
.value('config.build.build', 'Unknown')
.value('config.build.analyticsIdIos', undefined)
.value('config.build.analyticsIdAndroid', undefined)
.value('config.build.analyticsIdOther', undefined)
.value('config.build.admobIdIosBanner', undefined)
.value('config.build.admobIdIosInterstitial', undefined)
.value('config.build.admobIdAndroidBanner', undefined)
.value('config.build.admobIdAndroidInterstitial', undefined)
.value('config.build.admobIdOtherBanner', undefined)
.value('config.build.admobIdOtherInterstitial', undefined)
.constant('config.build.version', 'Unknown')
.constant('config.build.build', 'Unknown')
.constant('config.build.analyticsIdIos', undefined)
.constant('config.build.analyticsIdAndroid', undefined)
.constant('config.build.analyticsIdOther', undefined)
.constant('config.build.admobIdIosBanner', undefined)
.constant('config.build.admobIdIosInterstitial', undefined)
.constant('config.build.admobIdAndroidBanner', undefined)
.constant('config.build.admobIdAndroidInterstitial', undefined)
.constant('config.build.admobIdOtherBanner', undefined)
.constant('config.build.admobIdOtherInterstitial', undefined)
.constant('config.build.ionicPublicKey', undefined)
;

}());
103 changes: 103 additions & 0 deletions src/scripts/opennms/services/Ionic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
(function() {
'use strict';

/* global cordova: true */
/* global ionic: true */

angular.module('opennms.services.Ionic', [
'ionic',
'ionic.service.core',
'ionic.service.deploy',
'ngCordova',
'opennms.services.BuildConfig',
'opennms.services.Config',
'opennms.services.Settings',
])
.config(['$ionicAppProvider', 'config.build.ionicPublicKey', function($ionicAppProvider, ionicPublicKey) {
if (ionicPublicKey) {
console.log('Public key set. Initializing.');
$ionicAppProvider.identify({
// The App ID (from apps.ionic.io) for the server
app_id: 'bf988c24',
// The public API key all services will use for this app
api_key: ionicPublicKey
});
}
}])
.factory('IonicService', ['$q', '$ionicDeploy', '$ionicPopup', 'config.build.ionicPublicKey', function($q, $ionicDeploy, $ionicPopup, ionicPublicKey) {
var rejected = $q.defer();
rejected.reject(false);

$ionicDeploy.setChannel('Dev');

var checkForUpdates = function() {
var deferred = $q.defer();

if (!ionicPublicKey) {
console.log('Ionic.checkForUpdates: skipping, no public key configured.');
deferred.reject(false);
return deferred.promise;
}

console.log('Ionic.checkForUpdates: checking for updates.');
$ionicDeploy.check().then(function(hasUpdate) {
console.log('Ionic.checkForUpdates: hasUpdate = ' + hasUpdate);
deferred.resolve(hasUpdate);
}, function(err) {
console.log('Ionic.checkForUpdates: failed: ' + angular.toJson(err));
deferred.reject(err);
});

return deferred.promise;
};

var promptForUpdates = function() {
if (!ionicPublicKey) {
console.log('Ionic.promptForUpdates: skipping, no public key configured.');
return rejected.promise;
}

return checkForUpdates().then(function(hasUpdate) {
if (hasUpdate) {
return $ionicPopup.confirm({
title: 'Update Compass?',
template: 'OpenNMS Compass has an update. Install now?',
cancelText: 'Not now.',
cancelType: 'button-default',
okType: 'button-compass',
});
} else {
return false;
}
}, function(err) {
console.log('Ionic.promptForUpdates: failed: ' + angular.toJson(err));
return false;
});
};

var doUpdate = function() {
if (!ionicPublicKey) {
console.log('Ionic.doUpdate: skipping, no public key configured.');
return rejected.promise;
}

console.log('Ionic.doUpdate: updating app.');
return $ionicDeploy.update().then(function(res) {
console.log('Ionic.doUpdate: success! ' + angular.toJson(res));
return true;
}, function(err) {
console.log('Ionic.doUpdate: failed: ' + angular.toJson(err));
return false;
}, function(progress) {
console.log('Ionic.doUpdate: progress: ' + angular.toJson(progress));
});
};

return {
checkForUpdates: checkForUpdates,
promptForUpdates: promptForUpdates,
update: doUpdate,
};
}]);

}());

0 comments on commit e8a1675

Please sign in to comment.