From ff1cc0b2815d8b6564b03cbb997bd4496464b800 Mon Sep 17 00:00:00 2001 From: Matt Driscoll Date: Wed, 14 Sep 2016 11:40:01 -0700 Subject: [PATCH] 3.18 updates --- README.md | 2 +- config/defaults.js | 4 +- index.html | 4 +- instagram-callback.html | 45 +++++++++ js/InstagramLayer.js | 45 ++++----- js/SocialLayers.js | 160 +++++++++++++++++++++++++------- js/WebcamsLayer.js | 104 +++++++++++---------- js/main.js | 12 +++ js/nls/ar/resources.js | 4 +- js/nls/cs/resources.js | 4 +- js/nls/da/resources.js | 4 +- js/nls/de/resources.js | 4 +- js/nls/el/resources.js | 4 +- js/nls/es/resources.js | 4 +- js/nls/et/resources.js | 4 +- js/nls/fi/resources.js | 4 +- js/nls/fr/resources.js | 4 +- js/nls/he/resources.js | 4 +- js/nls/hr/resources.js | 4 +- js/nls/it/resources.js | 4 +- js/nls/ja/resources.js | 4 +- js/nls/ko/resources.js | 4 +- js/nls/lt/resources.js | 4 +- js/nls/lv/resources.js | 4 +- js/nls/nb/resources.js | 4 +- js/nls/nl/resources.js | 4 +- js/nls/pl/resources.js | 4 +- js/nls/pt-br/resources.js | 4 +- js/nls/pt-pt/resources.js | 4 +- js/nls/resources.js | 4 +- js/nls/ro/resources.js | 4 +- js/nls/ru/resources.js | 4 +- js/nls/sr/resources.js | 4 +- js/nls/sv/resources.js | 4 +- js/nls/th/resources.js | 4 +- js/nls/tr/resources.js | 4 +- js/nls/vi/resources.js | 4 +- js/nls/zh-cn/resources.js | 4 +- js/nls/zh-hk/resources.js | 4 +- js/nls/zh-tw/resources.js | 4 +- resources/configurationPanel.js | 50 ++-------- twitter-callback.html | 30 ++++++ 42 files changed, 402 insertions(+), 182 deletions(-) create mode 100644 instagram-callback.html create mode 100644 twitter-callback.html diff --git a/README.md b/README.md index e047e5f..f87bf5e 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ The template can be configured using the following options: 3. Change the sharing host, found in defaults.js inside the config folder for the application, to the sharing URL for ArcGIS Online or Portal. For ArcGIS Online users, keep the default value of www.arcgis.com or specify the name of your organization. - ArcGIS Online Example: `"sharinghost": location.protocol + "//" + “.maps.arcgis.com` - Portal Example where `arcgis` is the name of the Web Adaptor: `"sharinghost": location.protocol + "//" + "webadaptor.domain.com/arcgis"` -4. If you are using Portal or a local install of the ArcGIS API for JavaScript, change all references to the ArcGIS API for JavaScript in index.html to refer to your local copy of the API. Search for the references containing `"//js.arcgis.com/3.17"` and replace this portion of the reference with the url to your local install. +4. If you are using Portal or a local install of the ArcGIS API for JavaScript, change all references to the ArcGIS API for JavaScript in index.html to refer to your local copy of the API. Search for the references containing `"//js.arcgis.com/3.18"` and replace this portion of the reference with the url to your local install. - For example: `"//webadaptor.domain.com/arcgis/jsapi/jsapi"` where `arcgis` is the name of your Web Adaptor. 5. Copy a map or group ID from Portal/ArcGIS Online and replace the default web map ID in the application’s index.html page. You can now run the application on your web server or customize the application further. diff --git a/config/defaults.js b/config/defaults.js index c972a1a..f591537 100755 --- a/config/defaults.js +++ b/config/defaults.js @@ -51,7 +51,6 @@ define({ "hideNotesLayerPopups": true, "enableInstagram": true, "instagramVisible": false, - "instagramTime": "", "enableFlickr": true, "flickrVisible": false, "flickrSearch": "", @@ -71,7 +70,8 @@ define({ "twitterSigninUrl": location.protocol + "//utility.arcgis.com/tproxy/signin", "flickr_key": "404ebea7d5bc27aa5251d1207620e99b", "webcams_key": "65939add1ebe8bc9cc4180763f5df2ca", - "instagram_key": "288c36a1a42c49de9a2480a05d054619", + "instagramClientId": "47ce2d7ea1494adb98708f4b47319227", + "instagramSigninUrl": "https://www.instagram.com/oauth/authorize", "youtube_key": "AIzaSyBvrlsx50mxX_W-Ra2cJ8PB0jKt0jACZfg", /* "bannedUsersService": location.protocol + "//services.arcgis.com/QJfoC7c7Z2icolha/ArcGIS/rest/services/fai/FeatureServer/2", diff --git a/index.html b/index.html index 40c101e..213d62d 100755 --- a/index.html +++ b/index.html @@ -24,7 +24,7 @@ - + @@ -115,7 +115,7 @@ dojoConfig.locale = RegExp.$1; } - + + + + + + + + + diff --git a/js/InstagramLayer.js b/js/InstagramLayer.js index b4e332a..785d478 100755 --- a/js/InstagramLayer.js +++ b/js/InstagramLayer.js @@ -37,7 +37,7 @@ function ( filterWords: [], autopage: true, visible: true, - maxpage: 3, + maxpage: 10, limit: 100, title: 'Instagram', id: 'instagram', @@ -47,9 +47,9 @@ function ( maxScale: null, symbol: null, infoTemplate: null, - time: 5, // from the past days: 1, 2, 3, 4, 5, 6, 7 - key: '', + key: "", refreshTime: 4000, + token: "", url : 'https://api.instagram.com/v1/media/search/' }, constructor: function (options) { @@ -74,7 +74,6 @@ function ( this.set("minScale", defaults.minScale); this.set("maxScale", defaults.maxScale); this.set("refreshTime", defaults.refreshTime); - this.set("time", defaults.time); this.set("graphics", []); this.set("noGeo", []); // listeners @@ -269,24 +268,14 @@ function ( distance : radius }; }, - _getTimestamp: function(){ - var days = parseInt(this.get("time"), 10) || 5; - var d = new Date(); - d.setDate(d.getDate() - days); - return Math.round(d.getTime() / 1000); - }, _constructQuery: function () { - var unix_timestamp = this._getTimestamp(); var radius = this._getRadius(); this.query = { - client_id: this.key, count: this.limit, - lat: radius.lat, - lng: radius.lng, - min_timestamp: unix_timestamp, - max_timestamp: Math.round(new Date().getTime() / 1000), - distance: radius.distance, - page: 1, + lat: radius.lat, + lng: radius.lng, + distance: radius.distance, + access_token: this.token, format: "json" }; // make the actual API call @@ -304,12 +293,18 @@ function ( preventCache: true, load: lang.hitch(this, function (data) { if (data.meta && data.meta.code === 200) { + if(!this.get("authorized")){ + this.set("authorized", true); + this.emit("authorize", { + authorized: true + }); + } if (data.data.length > 0) { this._mapResults(data); // display results for multiple pages - if ((this.autopage) && (this.maxpage > this.pageCount) && (data.data.length === this.limit) && (this.query)) { + if ((this.autopage) && (!this.maxpage || this.maxpage > this.pageCount) && data.pagination && data.pagination.next_max_id) { this.pageCount++; - this.query.page++; + this.query.max_id = data.pagination.next_max_id; this._sendRequest(this.url, this.query); } else { this._updateEnd(); @@ -320,6 +315,12 @@ function ( } } else { if(data.meta){ + if(data.meta.code === 400){ + this.set("authorized", false); + this.emit("authorize", { + authorized: false + }); + } console.log('Instagram::' + data.meta.code + ' - ' + this.title + ': ' + data.meta.error_message); } // No results found, try another search term @@ -377,7 +378,9 @@ function ( result.height = result.images.thumbnail.height; result.username = result.user.username; result.full_name = result.user.full_name; - result.location_name = result.location.name; + if(result.location){ + result.location_name = result.location.name; + } // eliminate geo photos which we already have on the map if (this._dataIds[result.id]) { return; diff --git a/js/SocialLayers.js b/js/SocialLayers.js index 8a3f015..10dffc6 100644 --- a/js/SocialLayers.js +++ b/js/SocialLayers.js @@ -38,6 +38,34 @@ define([ Dialog, keys ) { + + var INSTAGRAM_ACCESS_TOKEN = "instagram_access_token"; + + function parseParms(str) { + var pieces = str.replace("#", "").split("&"), data = {}, i, parts; + // process each query pair + for (i = 0; i < pieces.length; i++) { + parts = pieces[i].split("="); + if (parts.length < 2) { + parts.push(""); + } + data[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]); + } + return data; + } + + // Feature test + function lsTest(){ + var test = 'test'; + try { + localStorage.setItem(test, test); + localStorage.removeItem(test); + return true; + } catch(e) { + return false; + } + } + return declare("", null, { initSocial: function () { // css classes for social layers @@ -161,11 +189,16 @@ define([ } // instagram enabled if (this.config.enableInstagram) { + var token = ""; + if(lsTest()){ + token = localStorage.getItem(INSTAGRAM_ACCESS_TOKEN) || ""; + } // Instagram this._instagramLayer = new InstagramLayer({ map: this.map, - visible: this.config.instagramVisible, - key: this.config.instagram_key + token: token, + key: this.config.instagramClientId, + visible: this.config.instagramVisible }); // legend info this.socialLayers.push({ @@ -174,6 +207,9 @@ define([ id: 'instagram_cog', className: "esri-icon-settings layerListIcon" }), + content: domConstruct.create("div", { + id: 'instagram_auth_status' + }), id: this._instagramLayer.featureLayer.id, visibility: this._instagramLayer.featureLayer.visible, layer: this._instagramLayer.featureLayer @@ -208,23 +244,12 @@ define([ configureSocial: function () { // instagram enabled if (this.config.enableInstagram) { - if (!this.config.instagramTime) { - this.config.instagramTime = 5; - } // Instagram Dialog var igContent = ''; igContent += '
'; igContent += '
' + this.config.i18n.social.igSettingsInfo + '
'; - igContent += '
' + this.config.i18n.social.igTime + '
'; - igContent += '
'; + igContent += '
' + this.config.i18n.social.instagramUser + '
'; + igContent += '
' + this.config.i18n.social.instagramAccountStatus + '
'; igContent += '
' + this.config.i18n.social.search + '
'; igContent += '
'; var instagramDialogNode = domConstruct.create('div', { @@ -254,6 +279,57 @@ define([ this._updateInstagramSearch(); })); } + // sign in/switch instagram node + this._instagramStatusNode = dom.byId('instagram_auth_status'); + this._instagramStatus2Node = dom.byId('instagram_settings_auth'); + this._instagramStatus3Node = dom.byId('instagram_legend_auth'); + if (this._instagramStatusNode) { + // sign in click + on(this._instagramStatusNode, 'a:click', lang.hitch(this, function (evt) { + this._instagramSignIn(evt); + })); + } + if (this._instagramStatus2Node) { + // sign in click + on(this._instagramStatus2Node, 'a:click', lang.hitch(this, function (evt) { + this._instagramSignIn(evt); + })); + } + if (this._instagramStatus3Node) { + // sign in click + on(this._instagramStatus3Node, 'a:click', lang.hitch(this, function (evt) { + this._twitterSignIn(evt); + })); + } + // authorize check + on(this._instagramLayer, 'authorize', lang.hitch(this, function (evt) { + var status, longStatus; + // user signed in + if (evt.authorized) { + status = '' + this.config.i18n.general.switchAccount + ''; + if (this._instagramStatusNode) { + this._instagramStatusNode.innerHTML = ''; + } + if (this._instagramStatus2Node) { + this._instagramStatus2Node.innerHTML = status; + } + if (this._instagramStatus3Node) { + this._instagramStatus3Node.innerHTML = ''; + } + } else { + status = '' + this.config.i18n.general.signIn + ''; + longStatus = '' + this.config.i18n.social.instagramSignIn + ''; + if (this._instagramStatusNode) { + this._instagramStatusNode.innerHTML = status; + } + if (this._instagramStatus2Node) { + this._instagramStatus2Node.innerHTML = status; + } + if (this._instagramStatus3Node) { + this._instagramStatus3Node.innerHTML = longStatus; + } + } + })); } // flickr enabled if (this.config.enableFlickr) { @@ -482,17 +558,6 @@ define([ this._updateYouTubeFilter(); } }, - _createInstagramOption: function (value) { - var html = '