Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
Markionium committed May 28, 2015
0 parents commit 50a24a1
Show file tree
Hide file tree
Showing 11 changed files with 547 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.iml
*.zip

node_modules
jspm_packages

.sass-cache
build


86 changes: 86 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
'use strict';

const BUILD_DIR = 'build';

const gulp = require('gulp');

gulp.task('clean', function (cb) {
var del = require('del');

del(BUILD_DIR, cb);
});

gulp.task('build-deploy', function (cb) {
var runSequence = require('run-sequence');
runSequence('clean', ['app', 'pack', 'deps', 'sass'], 'deploy');
});

gulp.task('build-prod', function (cb) {
var runSequence = require('run-sequence');
runSequence('clean', ['app', 'pack', 'deps', 'sass'], 'zip');
});

gulp.task('zip', function () {
var zip = require('gulp-zip');

return gulp.src(['./build/**'])
.pipe(zip('where-is-my-mechanism.zip'))
.pipe(gulp.dest('.'));
});

gulp.task('pack', function (cb) {
var Builder = require('systemjs-builder');
var builder = new Builder({});

builder.loadConfig('./src/config.js')
.then(function () {
builder.config({
paths: {
'json': './src/*.js',
'app': './src/*.js'
},
meta: {
'manifest.webapp!json': { build: false},
'manifest.webapp': { build: false}
}
});

return builder.build('app', BUILD_DIR + '/wimm.js', { minify: true, mangle: false, sourceMaps: true })
.then(function () {
cb();
})
.catch(function (error) {
console.log(error);
});
});
});

gulp.task('app', function () {
return gulp.src([
'src/**/*.{html,png}',
'src/config.js',
'src/manifest.webapp'
])
.pipe(gulp.dest(BUILD_DIR));
});

gulp.task('deps', function () {
return gulp.src(['jspm_packages/*'])
.pipe(gulp.dest([BUILD_DIR, 'jspm_packages'].join('/')));
});

gulp.task('sass', function () {
var rubySass = require('gulp-ruby-sass');
return rubySass(['./src/app.sass'], {loadPath: './src', style: 'expanded', compass: true})
.on('error', function (err) {
console.error('Error!', err.message);
})
.pipe(gulp.dest(
[BUILD_DIR, 'css'].join('/')
));
});

gulp.task('deploy', function () {
return gulp.src(['./build/**'])
.pipe(gulp.dest('/Users/markadm/Projects/dhis/DHIS2_HOME/apps/where-is-my-mechanism'));
});
36 changes: 36 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "where-is-my-mechanism",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Mark Polak",
"license": "BSD",
"jspm": {
"directories": {},
"configFile": "src/config.js",
"dependencies": {
"angular": "npm:angular@^1.4.0",
"jquery": "github:components/jquery@^2.1.4",
"systemjs/plugin-json.git": "github:systemjs/plugin-json@^0.1.0"
},
"devDependencies": {
"babel": "npm:babel-core@^5.1.13",
"babel-runtime": "npm:babel-runtime@^5.1.13",
"core-js": "npm:core-js@^0.9.4"
}
},
"devDependencies": {
"del": "^1.2.0",
"gulp": "^3.8.11",
"gulp-dev": "0.0.2",
"gulp-ruby-sass": "^1.0.5",
"gulp-zip": "^3.0.2",
"systemjs-builder": "^0.10.6"
},
"dependencies": {
"babel": "^5.4.7"
}
}
169 changes: 169 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
'use strict';
import 'jquery';
import angular from 'angular';

import manifest from 'manifest.webapp!json';

class WhereIsMyMechController {
constructor($http, $scope, $location) {
this.headerMap = {
Date: 'Date',
OperatingUnit: 'OU',
FiscalYear: 'FY',
PlanningReportingCycle: 'Reporting Cycle',
HQMechanismID: 'HQ ID',
LegacyMechanismID: 'Legacy ID',
ImplementingMechanismName: 'IM',
FundingAgency: 'Funding Agency',
PrimePartner: 'Prime Partner',
PrimePartnerID: 'Partner ID',
StartDate: 'Start Date',
EndDate: 'End Date',
Active: 'Active'
};

this.myMechanismSearchString = '';
this.api = $http;
this.datimInfo = {};
this.location = $location;

$scope.$watch(() => this.myMechanismSearchString, (newVal, oldVal) => {
if (newVal !== oldVal) {
this.search();
}
});

//Set the predefined search if we have one and run the search against the server
if ($location.$$search.query) {
this.myMechanismSearchString = $location.$$search.query;
this.search();
}
}

setSearchString(value) {
this.myMechanismSearchString = value.replace(/\"/g, '').trim();
}

search() {
//Reset found flags
this.foundInDatim = false;
this.foundInFactsInfo = false;
this.datimInfo = {};

this.location.search('query', this.myMechanismSearchString);

this.api.get('//sync.datim.org:1777/?search=' + this.myMechanismSearchString)
.then(this.buildResultList.bind(this))
.then(this.setResultList.bind(this))
.then((resultList) => {
if (resultList.length > 0) {
this.foundInFactsInfo = true;
return resultList[0];
}
return [];
})
.then(this.loadDATIMMechanism.bind(this));
}

buildResultList(response) {
let lines = response.data;
let headers = lines.shift();

return {
headers: headers,
lines: lines
.map(line => {
line[line.length - 1] = parseInt(line[line.length - 1], 10);
return line;
})
};
}

setResultList(resultList) {
if (!this.headers) {
this.headers = resultList.headers;
}
this.resultList = resultList.lines;

return this.resultList;
}

loadDATIMMechanism(firstRow) {
if (firstRow) {
this.datimMechanismCodeToSearch = firstRow[4];
} else {
this.datimMechanismCodeToSearch = this.myMechanismSearchString;
}

this.api.get('manifest.webapp')
.then(response => {
return response.data;
})
.then(manifest => {
return manifest.activities.dhis.href;
})
.then(apiUrl => {
return this.api.get([apiUrl, 'api', 'categoryOptions.json?filter=code:eq:' + this.datimMechanismCodeToSearch + '&fields=:all'].join('/'));
})
.then(response => response.data.categoryOptions[0])
.then(categoryOption => {
if (categoryOption) {
this.foundInDatim = true;
this.datimInfo.mechanism = categoryOption;
}

if (categoryOption && categoryOption.categoryOptionGroups.length > 0) {
this.datimInfo.agency = categoryOption.categoryOptionGroups.filter(categoryOptionGroup => /^Agency_.+/.test(categoryOptionGroup.code)).reduce((current) => current);
this.datimInfo.partner = categoryOption.categoryOptionGroups.filter(categoryOptionGroup => /^Partner_.+/.test(categoryOptionGroup.code)).reduce((current) => current);
}
});

}
}

function initMenu() {
//Setup dhis2 global for the menu
window.dhis2 = window.dhis2 || {};
dhis2.settings = dhis2.settings || {};
dhis2.settings.baseUrl = manifest.activities.dhis.href.replace(window.location.origin, '').replace(/^\//, '');

System.config({
paths: {
'commons:*': window.location.origin + '/' + dhis2.settings.baseUrl + '/dhis-web-commons/javascripts/dhis2/*.js'
}
});
let menuFiles = [
'dhis2.translate',
'dhis2.menu',
'dhis2.menu.ui'
];

let stylesheets = [
'/dhis-web-commons/font-awesome/css/font-awesome.min.css',
'/dhis-web-commons/css/menu.css'
];
let headElement = angular.element(document.querySelector('head'));
stylesheets.forEach(stylesheetUrl => {
let styleSheetElement = angular.element('<link href="' + window.location.origin + dhis2.settings.baseUrl + stylesheetUrl + '" rel="stylesheet" type="text/css" />');
angular.element(document.querySelector('head'))
.append(styleSheetElement);
});

return new Promise(function (resolve, reject) {
let result = Promise.resolve([]);
menuFiles.forEach(menuFile => {
result = result.then(function () {
return System.import('commons:' + menuFile);
});
});

resolve(result);
});
}

angular.module('whereIsMyMech', ['d2HeaderBar'])
.controller('WhereIsMyMechController', WhereIsMyMechController);

initMenu()
.then(() => angular.bootstrap(document.querySelector('html'), ['whereIsMyMech']))
.catch(() => window.console.log('Failed to bootstrap the app'));
Loading

0 comments on commit 50a24a1

Please sign in to comment.