Skip to content

Commit b74ce0d

Browse files
committed
update developer to support subwidget
1 parent 883bebe commit b74ce0d

File tree

9 files changed

+285
-217
lines changed

9 files changed

+285
-217
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ If you're not using the builder interface, this version extracts Web AppBuilder,
2626
1. Install Node.js.
2727
1. `npm install -g grunt-cli` (see https://gruntjs.com/getting-started)
2828
1. Clone or download this repo.
29-
1. Download the Web AppBuilder Developer Edition zip file from [here](https://developers.arcgis.com/web-appbuilder/), and save the zip file named `arcgis-web-appbuilder-2.9.zip` into the `developer/` folder, right at the same level as the `Gruntfile.js`.
29+
1. Download the Web AppBuilder Developer Edition zip file from [here](https://developers.arcgis.com/web-appbuilder/), and save the zip file named `arcgis-web-appbuilder-2.11.zip` into the `developer/` folder, right at the same level as the `Gruntfile.js`.
3030
1. In the terminal, browse to the `developer` folder
3131
1. `npm install`
3232
1. `grunt init`

developer/Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module.exports = function(grunt) {
7777
}
7878
},
7979
unzip: {
80-
'temp/': 'arcgis-web-appbuilder-2.9.zip'
80+
'temp/': 'arcgis-web-appbuilder-2.12.zip'
8181
},
8282
connect: {
8383
server: {

developer/app/env.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////
2-
// Copyright © 2014 - 2018 Esri. All Rights Reserved.
2+
// Copyright © Esri. All Rights Reserved.
33
//
44
// Licensed under the Apache License Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -77,7 +77,7 @@ var
7777

7878
//This version number will be appended to URL to avoid cache.
7979
//The reason we do not use wabVersion is to avoid force user to change wabVersion when they are customizing app.
80-
deployVersion = '2.9';
80+
deployVersion = '2.12';
8181

8282
// console.time('before map');
8383

@@ -90,18 +90,24 @@ var
9090
(function(global){
9191
//init API URL
9292
var queryObject = getQueryObject();
93-
var apiVersion = '4.8';
93+
var apiVersion = '4.11';
9494
////////uncomment the following line when downloading the app
9595

96-
apiUrl = 'https://js.arcgis.com/4.8';
96+
apiUrl = 'https://js.arcgis.com/4.11';
9797

9898
//////////////////////////////////////////////////////////////
9999
allCookies = getAllCookies();
100100
window.appInfo = {isRunInPortal: !isXT};
101+
102+
if (queryObject.apiurl3d) {
103+
if(!checkApiUrl(queryObject.apiurl3d)){
104+
console.error('?apiurl must point to an ULR that is in the app or in esri.com/arcgis.com domain.');
105+
return;
106+
}
107+
apiUrl = queryObject.apiurl3d;
108+
}
101109
if (!apiUrl) {
102-
if (queryObject.apiurl3d) {
103-
apiUrl = queryObject.apiurl3d;
104-
} else if (isXT) {
110+
if (isXT) {
105111
apiUrl = 'https://js.arcgis.com/' + apiVersion;
106112
} else {
107113
var portalUrl = getPortalUrlFromLocation();
@@ -141,6 +147,14 @@ var
141147
return cookies;
142148
}
143149

150+
function checkApiUrl(url){
151+
if(/^\/\//.test(url) || /^https?:\/\//.test(url)){
152+
return /(?:[\w\-\_]+\.)+(?:esri|arcgis)\.com/.test(url); //api url must be in esri.com or arcgis.com
153+
}else{
154+
return true;
155+
}
156+
}
157+
144158
function getPortalUrlFromLocation(){
145159
var portalUrl = getPortalServerFromLocation() + getDeployContextFromLocation();
146160
return portalUrl;
@@ -152,9 +166,9 @@ var
152166
}
153167

154168
function getDeployContextFromLocation (){
155-
var keyIndex = window.location.href.indexOf("/home");
169+
var keyIndex = window.location.href.indexOf("/home/");
156170
if(keyIndex < 0){
157-
keyIndex = window.location.href.indexOf("/apps");
171+
keyIndex = window.location.href.indexOf("/apps/");
158172
}
159173
var context = window.location.href.substring(window.location.href.indexOf(
160174
window.location.host) + window.location.host.length + 1, keyIndex);

developer/app/widgets/Demo/Widget.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import FeatureSet from 'esri/tasks/support/FeatureSet';
1212
import Query from 'esri/tasks/support/Query';
1313
import SceneView from 'esri/views/SceneView';
1414

15-
// Dojo imports:
16-
// import * as on from 'dojo/on';
15+
// dojo imports:
16+
// import on from 'dojo/on';
17+
18+
import IConfig from './config';
19+
import Subwidget from './widgets/Subwidget';
1720

18-
interface IConfig {
19-
demoSetting: string;
20-
}
2121
interface IWidget {
2222
baseClass: string;
2323
config?: IConfig;
@@ -30,12 +30,20 @@ class Widget implements IWidget {
3030

3131
private sceneView: SceneView;
3232
private widgetWrapper: HTMLElement;
33+
private subwidget: Subwidget;
3334

34-
private postCreate(args: any) {
35+
private postCreate(args: any): void {
3536
const self: any = this;
3637
self.inherited(arguments);
38+
3739
this.widgetWrapper.innerHTML = this.config.demoSetting;
3840
this.createLayer();
41+
42+
// create a new instance of "Subwidget" wich is just a plain old dojo Widget.
43+
this.subwidget = new Subwidget({
44+
text: 'This is a subwidget.'
45+
});
46+
this.subwidget.placeAt(this.widgetWrapper, 'last');
3947
}
4048

4149
/**

developer/app/widgets/Demo/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default interface IConfig {
2+
demoSetting: string;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
Subwidget!
3+
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <amd-dependency path="dojo/text!./Subwidget.html" name="template" />
2+
declare var template: any;
3+
4+
import declare from '../support/declareDecorator';
5+
import WidgetBase from 'dijit/_WidgetBase';
6+
import _TemplatedMixin from 'dijit/_TemplatedMixin';
7+
import _WidgetsInTemplateMixin from 'dijit/_WidgetsInTemplateMixin';
8+
9+
// This line tells Typescript that our Subwidget extends from WidgetBase,
10+
// so when we call built-in properties or functions (like .placeAt()),
11+
// Typescript will not error:
12+
interface Subwidget extends WidgetBase {};
13+
14+
@declare(WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin)
15+
class Subwidget {
16+
private templateString: string = template;
17+
18+
baseClass: string = 'subwidget';
19+
20+
constructor(params?: any, srcNodeRef?: dojo.NodeOrString) {
21+
// lang.mixin(this, params);
22+
}
23+
}
24+
25+
export default Subwidget;

0 commit comments

Comments
 (0)