Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update OS domain #115

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
var path = require('path');
var nconf = require('nconf');

var DEFAULT_HOST = 'https://openspending.org';
var DEFAULT_BASE_PATH = '';
const DEFAULT_HOST = 'https://openspending.org';
const DEFAULT_BASE_PATH = '';

nconf.file({
file: path.join(__dirname, '/../../settings.json')
Expand Down
85 changes: 83 additions & 2 deletions app/front/scripts/controllers/download-package.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use strict';
var osAdminService = require('../services/admin');

angular.module('Application')
.controller('DownloadPackageController', [
'$scope', 'PackageService', 'DownloadPackageService',
'Configuration', 'ApplicationLoader', 'LoginService',
'Configuration', 'ApplicationLoader', 'LoginService', '$interval', '$http', '$window',
function($scope, PackageService, DownloadPackageService,
Configuration, ApplicationLoader, LoginService) {
Configuration, ApplicationLoader, LoginService, $interval, $http, $window) {

ApplicationLoader.then(function() {
$scope.fileName = Configuration.defaultPackageFileName;
$scope.attributes = PackageService.getAttributes();
Expand All @@ -16,6 +18,85 @@ angular.module('Application')
$scope.login = LoginService;
$scope.publishDataPackage = DownloadPackageService.publishDataPackage;
$scope.state = DownloadPackageService.getState(true);
$scope.packageOBEUStatus = null;
$scope.obeuUrl = 'http://apps.openbudgets.eu'
});


$scope.publishAndRunWebHooks = function () {
$scope.publishDataPackage().finally(function (res) {
runWebHooks($scope.fiscalDataPackage.name);
});
};


$scope.redirectToViewer = function() {
console.log('querying');
var url = $scope.obeuUrl + '/search/package?q=' + encodeURIComponent($scope.fiscalDataPackage.name) + '&size=1';
$http.get(url, {withCredentials: false}).then(
function (res) {
console.log('good');
var packageId = '';
if (res.length > 0) {
packageId = res[0].name;
}
$window.open($scope.obeuUrl + '/' + packageId, '_blank');
},
function (err) {
console.log(err);
$window.open($scope.obeuUrl, '_blank');
}
)
};


function runWebHooks(packageId) {
$scope.packageOBEUStatus = 'processing';
// query data packages to extract the user's "owner id"
osAdminService.getDataPackages(LoginService.authToken, LoginService.userId).then(function (packages) {
console.log(packages);
var ownerId = packages[0].owner;
var dataPackageId = ownerId + ":" + packageId;

// set the data package status to "published" (a.k.a. public)
osAdminService.togglePackagePublicationStatus(LoginService.permissionToken, {id: dataPackageId}).then(
function (res) {
// run web hooks for the package
var dataPackage = _.find(packages, {id: dataPackageId});

if (dataPackage) {
var token = LoginService.permissionToken;
osAdminService.runWebHooks(token, dataPackage).then(function(res) {
var iri = JSON.parse(res.response).iri;
var executionId = iri.substr(1 + iri.lastIndexOf('/'), iri.length);
var executionOverviewUrl =
'http://apps.openbudgets.eu/linkedpipes/test/resources/executions/' + executionId + '/overview';
pollPipelineUntilReady(executionOverviewUrl);
});
}
}
);
},
function (err) {
console.log(err);
});
};

function pollPipelineUntilReady(executionOverviewUrl) {
stop = $interval(function () {
$http.get('https://crossorigin.me/' + executionOverviewUrl, {withCredentials: false}).then(
function (res) {
console.log(res);
if (res.data.status['@id'].includes('finished')) {
$interval.cancel(stop);
$scope.packageOBEUStatus = 'ready';
}
},
function (err) {
console.log(err);
}
);
}, 3000);
}
}
]);
Loading