From 84ba5f3bd7bbda9f91cba4a5985d51018b80a302 Mon Sep 17 00:00:00 2001 From: Ramya Ragupathy Date: Wed, 28 Mar 2018 10:44:29 +0530 Subject: [PATCH] #5, #7 polygon & mapping entitied for a project --- dist/bundle.js | 29 +++++++++++++++++++---------- js/app.js | 29 +++++++++++++++++++---------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/dist/bundle.js b/dist/bundle.js index 64b6cd1..8d8e0a8 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -987,23 +987,33 @@ function errorNotice (message, time) { } /** - * Event listener for project selection + * Construct URL to request a particular project details * **/ -document.getElementById('projects').addEventListener('change', function (e) { - let projectID = this.value - projDetails(projectID) -}) +function getProjQuery () { + let projectID = document.getElementById('projects').value + let url = 'https://tasks.hotosm.org/api/v1/project/' + projectID + '?as_file=false' + return url +} /** * Fetches complete details of a particular HOTOSM project * - * @param {number} projectID - Unique ID of a HOTOSM project **/ -function projDetails (projectID) { - console.log('From projDetails: ', projectID) +function getProjDetails () { + let url = getProjQuery() + console.log('From projDetails: ', url) + $.ajax(url) + .done(function (data) { + let polygon = data.areaOfInterest + let entities = data.mappingTypes + console.log(entities) + console.log(polygon) + }) + .fail(function () { + }) } // Fetch Data on Click @@ -1017,8 +1027,7 @@ $('#submit').on('click', function () { 'fromDate': moment($('#fromdate').val()).utc().toISOString(), 'toDate': moment($('#todate').val()).utc().toISOString() } - let url = getQuery() - console.log('from submit before fetching ', url) + getProjDetails() getData() } else { errorNotice('Zoom in further to fetch results') diff --git a/js/app.js b/js/app.js index cf46584..c54b390 100644 --- a/js/app.js +++ b/js/app.js @@ -178,23 +178,33 @@ function errorNotice (message, time) { } /** - * Event listener for project selection + * Construct URL to request a particular project details * **/ -document.getElementById('projects').addEventListener('change', function (e) { - let projectID = this.value - projDetails(projectID) -}) +function getProjQuery () { + let projectID = document.getElementById('projects').value + let url = 'https://tasks.hotosm.org/api/v1/project/' + projectID + '?as_file=false' + return url +} /** * Fetches complete details of a particular HOTOSM project * - * @param {number} projectID - Unique ID of a HOTOSM project **/ -function projDetails (projectID) { - console.log('From projDetails: ', projectID) +function getProjDetails () { + let url = getProjQuery() + console.log('From projDetails: ', url) + $.ajax(url) + .done(function (data) { + let polygon = data.areaOfInterest + let entities = data.mappingTypes + console.log(entities) + console.log(polygon) + }) + .fail(function () { + }) } // Fetch Data on Click @@ -208,8 +218,7 @@ $('#submit').on('click', function () { 'fromDate': moment($('#fromdate').val()).utc().toISOString(), 'toDate': moment($('#todate').val()).utc().toISOString() } - let url = getQuery() - console.log('from submit before fetching ', url) + getProjDetails() getData() } else { errorNotice('Zoom in further to fetch results')