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

call out to rest-js for a handful of methods #43

Merged
merged 7 commits into from
Dec 4, 2018
Merged
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## 1.6.1
### Fixed
- update token logic to handle cases where services have UPCASED server names, but portalHostname is lowercase.

## 1.6.0
### Changed
- fixed deploy script by installing ember-cli-github-pages
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Esri welcomes contributions from anyone and everyone. Please see our [guidelines

### License

Copyright (c) 2017 Esri
Copyright © 2017-2018 Esri

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
8 changes: 5 additions & 3 deletions addon/mixins/ags-service-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ export default Mixin.create({
return this.getLayerInfo(url, options);
},

getLayerInfo (url, options) {
return this.request(url + '?f=json', options);
},
// This method was also declared in the ags-service-mixin and was shadowing that implementation
// So it's removed now...
// getLayerInfo (url, options) {
// return this.request(url + '?f=json', options);
// },

/**
* Get the base server info.
Expand Down
38 changes: 27 additions & 11 deletions addon/mixins/layers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Mixin from '@ember/object/mixin';
import { parseServiceUrl } from '../utils/parse-url';
import encodeForm from '../utils/encode-form';
import { request } from '@esri/arcgis-rest-request';
import { queryFeatures, getLayer, getFeature } from '@esri/arcgis-rest-feature-service';
// to do: ember fetch?

export default Mixin.create({
init: function () {
Expand All @@ -16,17 +18,23 @@ export default Mixin.create({
const serviceUrl = parseServiceUrl(url);
layerUrl = `${serviceUrl}/${options.layer}`;
}
return this.request(layerUrl + '?f=json', options);

// previously we passed along options too. could something else have been in there?
return getLayer(layerUrl, {
authentication: this.get('session.authMgr')
});
},

/**
* Get info about all layers
*/
getLayersInfo (url, options) {
getLayersInfo (url) {
const serviceUrl = parseServiceUrl(url);
let layersUrl = `${serviceUrl}/layers?f=json`;
let layersUrl = `${serviceUrl}/layers`;
// make the request
return this.request(layersUrl, options)
return request(layersUrl, {
authentication: this.get('session.authMgr')
})
.then(layerInfo => {
const merged = [...layerInfo.layers, ...layerInfo.tables];
this.set('layers', merged);
Expand All @@ -39,16 +47,24 @@ export default Mixin.create({
* Search for records
*/
query (url, options) {
let encoded = encodeForm(options);
url = url + '/query?f=json&' + encoded;
return this.request(url, { method: 'GET' });
// no support for spread operators here :(
const queryOptions = Object.assign({
url,
httpMethod: "GET",
authentication: this.get('session.authMgr')
}, options);
return queryFeatures(queryOptions);
},

/**
* Get a record by id
*/
getById (url, id, options) {
url = `${url}/${id}?f=json`;
return this.request(url, options);
getById (url, id) {
return getFeature({
url,
id,
httpMethod: "GET",
authentication: this.get('session.authMgr')
});
}
});
74 changes: 56 additions & 18 deletions addon/services/feature-service.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,59 @@
import Service from '@ember/service';
import serviceMixin from '../mixins/ags-service-mixin';
import layerMixin from '../mixins/layers';
import {
getFeature,
addFeatures,
updateFeatures,
deleteFeatures,
getAttachments
} from "@esri/arcgis-rest-feature-service";

export default Service.extend(serviceMixin, layerMixin, {

/**
* Get a record by id
*/
getById (url, id) {
url = `${url}/${id}?f=json`;
return this.request(url, {method: 'GET'});
// why is there an optionless getById() here and another in mixins/layers.js?
return getFeature({
url,
id,
httpMethod: "GET"
});
},

/**
* Get attachments for a record by id
*/
getAttachmentsById (url, id) {
url = `${url}/${id}/attachments?f=json`;
return this.request(url, {method: 'GET'});
return getAttachments({
url,
featureId: id,
httpMethod: 'GET'
})
},

/**
* Update a single feature
*/
updateFeature (url, feature, token) {
return this.updateFeatures(url, [feature], token);
updateFeature (url, feature) {
return updateFeatures({
url,
features: [feature],
authentication: this.get('session.authMgr')
});
},

/**
* Update a set of features
*/
updateFeatures (url, features, token) {
return this.applyEdits(url, [], features, [], token);
updateFeatures (url, features) {
return updateFeatures({
url,
features,
authentication: this.get('session.authMgr')
});
},

/**
Expand All @@ -41,25 +63,32 @@ export default Service.extend(serviceMixin, layerMixin, {
* data.keywords
*/
updateAttachment (url, data, token) {
// the feature id must already be embedded in the url
url = url + '/updateAttachment?f=json';
return this.attachmentsRequest(url, data, token);
},

/**
* Add a single feature
*/
addFeature (url, feature, token) {
// wrap into an array...
let adds = [feature];
addFeature (url, feature) {
// delegate to addFeatures
return this.addFeatures(url, adds, token);
return addFeatures({
url,
features: [feature],
authentication: this.get('session.authMgr')
});
},

/**
* Add a set of features
*/
addFeatures (url, features, token) {
return this.applyEdits(url, features, [], [], token);
addFeatures (url, features) {
return addFeatures({
url,
features,
authentication: this.get('session.authMgr')
});
},

/**
Expand All @@ -75,15 +104,23 @@ export default Service.extend(serviceMixin, layerMixin, {
/**
* Delete a single feature
*/
deleteFeature (url, objectId, token) {
return this.deleteFeatures(url, [objectId], token);
deleteFeature (url, objectId) {
return deleteFeatures({
url,
objectIds: [objectId],
authentication: this.get('session.authMgr')
});
},

/**
* Delete a set of features
*/
deleteFeatures (url, objectIds, token) {
return this.applyEdits(url, [], [], objectIds, token);
deleteFeatures (url, objectIds) {
return deleteFeatures({
url,
objectIds,
authentication: this.get('session.authMgr')
});
},

/**
Expand All @@ -100,6 +137,7 @@ export default Service.extend(serviceMixin, layerMixin, {
* Actually send the edits to the Service
*/
applyEdits (url, adds, updates, deletes, token) {
// no equivalent method exists in rest-js (yet)
url = url + '/applyEdits';
let options = {
method: 'POST',
Expand Down
6 changes: 3 additions & 3 deletions addon/utils/should-add-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export default function shouldAddToken (url, serverInfo, portalInfo) {
// check if the server even accepts tokens
const acceptsTokens = getWithDefault(serverInfo, 'authInfo.isTokenBasedSecurity', false);
if (acceptsTokens) {
const serverDomain = stripToDomain(url);
const portalDomain = stripToDomain(portalInfo.portalHostname);
const owningDomain = stripToDomain(serverInfo.owningSystemUrl);
const serverDomain = stripToDomain(url).toLowerCase();
const portalDomain = stripToDomain(portalInfo.portalHostname).toLowerCase();
const owningDomain = stripToDomain(serverInfo.owningSystemUrl).toLowerCase();
const authorizedCrossOriginDomains = portalInfo.authorizedCrossOriginDomains || [];
const isAuthorizedUrl = authorizedCrossOriginDomains.indexOf(serverDomain) > -1;
const isArcGisDomain = !!url.toLowerCase().match('.arcgis.com/');
Expand Down
5 changes: 4 additions & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
let app = new EmberAddon(defaults, {
// Add options here
// config for ember-cli-babel
'ember-cli-babel': {
includePolyfill: true
}
});

/*
Expand Down
55 changes: 43 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
/* Copyright 2017 Esri
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
/* jshint node: true */
'use strict';
var path = require('path');
var Funnel = require('broccoli-funnel');
var MergeTrees = require('broccoli-merge-trees');

module.exports = {
name: require('./package').name
name: require('./package').name,

isDevelopingAddon: function () {
return false;
},

included (/* app */) {
this._super.included.apply(this, arguments);
// bundle scripts from vendor folder
this.import('vendor/@esri/arcgis-rest-request/request.umd.js');
this.import('vendor/@esri/arcgis-rest-feature-service/feature-service.umd.js');
this.import('vendor/shims/@esri/arcgis-rest-request.js');
this.import('vendor/shims/@esri/arcgis-rest-feature-service.js');
},

treeForVendor (vendorTree) {
var arcgisRequestTree = new Funnel(path.dirname(require.resolve('@esri/arcgis-rest-request/dist/umd/request.umd.js')), {
files: ['request.umd.js', 'request.umd.js.map'],
destDir: '@esri/arcgis-rest-request'
});

var arcgisFeatureServiceTree = new Funnel(path.dirname(require.resolve('@esri/arcgis-rest-feature-service/dist/umd/feature-service.umd.js')), {
files: ['feature-service.umd.js', 'feature-service.umd.js.map'],
destDir: '@esri/arcgis-rest-feature-service'
});

var treesToMerge = [
arcgisRequestTree,
arcgisFeatureServiceTree
];

// if we got a vendorTree, and add it in
if (vendorTree) {
treesToMerge.unshift(vendorTree);
}

return new MergeTrees(treesToMerge);
}
};
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
"lint:hbs": "ember-template-lint .",
"lint:js": "eslint .",
"start": "ember serve",
"test": "ember test",
"test": "npm run lint:js && ember test",
"test:all": "ember try:each --skip-cleanup",
"deploy": "ember github-pages:commit --environment=github --message \"Deploy gh-pages from commit $(git rev-parse HEAD)\";"
},
"dependencies": {
"@esri/arcgis-rest-feature-service": "^1.14.3",
"@esri/arcgis-rest-request": "^1.14.3",
"broccoli-funnel": "^2.0.1",
"broccoli-merge-trees": "^2.0.0",
"ember-cli-babel": "^6.16.0"
},
"devDependencies": {
Expand All @@ -44,7 +48,7 @@
"ember-cli-uglify": "^2.1.0",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-export-application-global": "^2.0.0",
"ember-fetch": "^3.4.5",
"ember-fetch": "^6.2.0",
"ember-load-initializers": "^1.1.0",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-qunit": "^3.4.1",
Expand All @@ -63,7 +67,7 @@
"eslint-plugin-standard": "^2.0.0",
"loader.js": "^4.7.0",
"qunit-dom": "^0.8.0",
"torii-provider-arcgis": "^2.2.0"
"torii-provider-arcgis": "^2.2.1"
},
"engines": {
"node": "6.* || 8.* || >= 10.*"
Expand Down
23 changes: 23 additions & 0 deletions tests/dummy/app/portal/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default Controller.extend({
session: service(),
featureService: service('feature-service'),
serviceUrl: 'https://PNP00035.esri.com/server/rest/services/Hosted/perimeters_dd83/FeatureServer',

actions: {
getLayerInfo () {
const serviceUrl = this.get('serviceUrl');
const options = {
authentication: this.get('session.authMgr')
};
return this.get('featureService').getLayerInfo(serviceUrl, options)
.then((layerInfo) => {
this.set('json', JSON.stringify(layerInfo, null, 2));
})
.catch((err) => {
this.set('json', JSON.stringify(err, null, 2));
})
}
}
});
5 changes: 5 additions & 0 deletions tests/dummy/app/portal/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Route from '@ember/routing/route';

export default Route.extend({

});
Loading