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

Commit

Permalink
feat(Mobile): Add server configuration to user preferences
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Jackson <chris@cd-jackson.com>
  • Loading branch information
cdjackson committed Jun 5, 2016
1 parent 6e82813 commit 5dd9cb3
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 17 deletions.
69 changes: 65 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
// grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-conventional-changelog');
Expand All @@ -22,7 +22,8 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-lesslint')
grunt.loadNpmTasks('grunt-lesslint');
grunt.loadNpmTasks('grunt-string-replace');

/**
* Load in our build configuration file.
Expand Down Expand Up @@ -708,6 +709,62 @@ module.exports = function (grunt) {
},
command: 'phonegap build android'
}
},

/**
* String Replace functions to update android manifest
*/
'string-replace': {
versionCode: { // update the version code stored in package.json
options: {
replacements: [
{
pattern: /['"]androidVersionCode['"]:.*?['"](\d*)['"]/ig,
replacement: function (match, p1, offset, string) {
return '"androidVersionCode": "' + (parseInt(p1) + 1) + '"';
}
}
]
},
files: {
'package.json': 'package.json'
}
},

androidVersionCode: { // update the version code stored in AndroidManifest.xml
options: {
replacements: [
{
pattern: /android:versionCode=['"](\d*)['"]/ig,
replacement: function (match, p1, offset, string) {
var pkg = grunt.file.readJSON('package.json');
grunt.log.writeln("pkg.androidVersionCode: " + pkg.androidVersionCode);
grunt.log.writeln('Returning: ' + 'android:versionCode="' + pkg.androidVersionCode + '"');
return 'android:versionCode="' + pkg.androidVersionCode + '"';
}
}
]
},
files: {
'cordova/platforms/android/AndroidManifest.xml': 'cordova/platforms/android/AndroidManifest.xml'
}
},
androidVersionName: { // update the version name stored in AndroidManifest.xml
options: {
replacements: [
{
pattern: /android:versionName=['"]([0-9.]*)['"]/ig,
replacement: function (match, p1, offset, string) {
var pkg = grunt.file.readJSON('package.json');
return 'android:versionName="' + pkg.version + '"';
}
}
]
},
files: {
'cordova/platforms/android/AndroidManifest.xml': 'cordova/platforms/android/AndroidManifest.xml'
}
}
}
};

Expand Down Expand Up @@ -820,14 +877,18 @@ module.exports = function (grunt) {
* Phonegap compiler - internal...
*/
grunt.registerTask('build_cordova', [
'copy:cordova_build', 'index:cordova', 'shell:build_android', 'copy:cordova_android'
'copy:cordova_build', 'index:cordova',
'string-replace:versionCode', 'string-replace:androidVersionCode', 'string-replace:androidVersionName',
'shell:build_android', 'copy:cordova_android'
]);

/**
* Phonegap compiler - internal...
*/
grunt.registerTask('compile_cordova', [
'copy:cordova_build', 'index:cordova', 'shell:build_android', 'copy:cordova_android'
'copy:cordova_build', 'index:cordova',
'string-replace:versionCode', 'string-replace:androidVersionCode', 'string-replace:androidVersionName',
'shell:build_android', 'copy:cordova_android'
]);

/**
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"author": "Chris Jackson",
"name": "HABmin2",
"version": "0.1.6",
"androidVersionCode": "2",
"homepage": "https://github.com/cdjackson/HABmin2",
"licenses": {
"type": "GPL",
Expand Down Expand Up @@ -39,6 +40,7 @@
"grunt-contrib-cssmin": "~0.11.0",
"grunt-shell": "~1.1.1",
"karma-chrome-launcher": "~0.1.8",
"grunt-lesslint": "~1.1.14"
"grunt-lesslint": "~1.1.14",
"grunt-string-replace": "~1.2.1"
}
}
8 changes: 6 additions & 2 deletions src/app/user/userConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ angular.module('User.Config', [
function ($scope, $q, locale, growl, $timeout, $window, $http, $interval, UserService, PersistenceServiceModel, localeSupported) {
$scope.panelDisplayed = 'GENERAL';

$scope.model = {currentLanguage: UserService.getLanguage(),
currentPersistence: UserService.getPersistence()
$scope.model = {
currentLanguage: UserService.getLanguage(),
currentPersistence: UserService.getPersistence(),
serverAddress: UserService.getServer()
};
$scope.languages = [];
var languageOk = false;
Expand Down Expand Up @@ -89,6 +91,8 @@ angular.module('User.Config', [
$scope.saveConfig = function () {
UserService.setLanguage($scope.model.currentLanguage);
UserService.setPersistence($scope.model.currentPersistence.name);
UserService.setServer($scope.model.serverAddress);

$scope.userConfigForm.$setPristine();
};

Expand Down
30 changes: 23 additions & 7 deletions src/app/user/userConfig.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@
<form name="userConfigForm" novalidate style="height:100%">
<!-- GENERAL -->
<div>
<a role="presentation"
ng-class="{'list-group-item config-panel-title':true, 'active': panelDisplayed=='GENERAL'}"
<a role="presentation" class="list-group-item config-panel-title"
ng-class="{'active': panelDisplayed=='GENERAL'}"
ng-click="setPanelDisplayed('GENERAL')">
<span class="fa fa-fw fa-book"></span>
<span i18n="user.GeneralPrefTitle"></span>
</a>
</div>
<div collapse="panelDisplayed!='GENERAL'" class="panel-form">
<div class="form-group">
<label for="inputLanguage" class="col-sm-3 control-label" i18n="user.Language"></label>
<label for="inputLanguage" class="control-label" i18n="user.Language"></label>

<div class="col-sm-9">
<ui-select id="inputLanguage"
ng-model="model.currentLanguage"
theme="bootstrap"
Expand All @@ -53,13 +52,11 @@
</div>
</ui-select-choices>
</ui-select>
</div>
</div>

<div class="form-group">
<label for="inputPersistence" class="col-sm-3 control-label" i18n="user.ChartPersistence"></label>
<label for="inputPersistence" class="control-label" i18n="user.ChartPersistence"></label>

<div class="col-sm-9">
<ui-select id="inputPersistence"
ng-model="model.currentPersistence"
theme="bootstrap"
Expand All @@ -72,6 +69,25 @@
</ui-select-choices>
</ui-select>
</div>
</div>

<!-- SERVER SETTINGS -->
<div ng-if="document.HABminCordova">
<a role="presentation" class="list-group-item config-panel-title"
ng-class="{'active': panelDisplayed=='SERVER'}"
ng-click="setPanelDisplayed('SERVER')">
<span class="fa fa-fw fa-desktop"></span>
<span i18n="user.ServerPrefTitle"></span>
</a>
</div>
<div collapse="panelDisplayed!='SERVER'" class="panel-form">
<div class="form-group">
<label for="inputServerAddress" class="control-label" i18n="user.ServerAddress"></label>

<input id="inputServerAddress"
class="form-control"
ng-dirty
ng-model="model.serverAddress">
</div>
</div>
</form>
Expand Down
2 changes: 1 addition & 1 deletion src/languages/en-GB/habmin.lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"Sitemaps": "Sitemaps",
"StatusOffline": "The server is offline!",
"StatusOnline": "The server is online.",
"Things": "Thing Configuration",
"Things": "Things",
"Tools": "Tools",
"UserPreferences": "My Preferences",
"Users": "Users",
Expand Down
3 changes: 1 addition & 2 deletions src/languages/en-GB/services.lang.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"ErrorGettingServices": "Error getting service list",
"Services": "Services"
"ErrorGettingServices": "Error getting service list"
}
2 changes: 2 additions & 0 deletions src/languages/en-GB/user.lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"Language": "Language",
"LanguageSelect": "Select your language...",
"Name": "Name",
"ServerAddress": "Address",
"ServerPrefTitle": "Server Settings",
"Theme": "Theme",
"ThemeSelect": "Select your theme..."
}

0 comments on commit 5dd9cb3

Please sign in to comment.