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

Config traits #5918

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3b89108
create configParametersModel and move from interface to trait system
zoran995 Oct 17, 2021
23c6840
run prettier
zoran995 Oct 17, 2021
d23b4f8
update parseConfigErrorMessage
zoran995 Oct 17, 2021
78cce0a
update references to changed parameters and fix tests
zoran995 Oct 17, 2021
3ed99f9
update help content item and terms traits
zoran995 Oct 17, 2021
ed87409
update docs
zoran995 Oct 17, 2021
7321176
update ci-values.yml
zoran995 Oct 17, 2021
3930928
update brandBar config to object trait
zoran995 Oct 17, 2021
1bd8406
Merge remote-tracking branch 'terriajs/rename-error-force-raise' into…
zoran995 Oct 20, 2021
551f928
add basic conversion from deprecated configParameters to avoid breaki…
zoran995 Oct 25, 2021
dd92b69
Merge remote-tracking branch 'terriajs/main' into config-traits
zoran995 Oct 25, 2021
dd48325
update CHANGES.md
zoran995 Oct 25, 2021
3cd7f55
Merge remote-tracking branch 'terriajs/main' into config-traits
zoran995 Nov 23, 2021
cb382ac
remove mobileDefaultViewerMode at start and mark it as not implemented
zoran995 Nov 23, 2021
e4b7771
add missing url trait to help content item
zoran995 Nov 23, 2021
7193ce0
wrap observables in action if in non-reactive context
zoran995 Nov 23, 2021
a3c4e87
fix geojson test
zoran995 Nov 23, 2021
3743ced
run prettier
zoran995 Nov 23, 2021
a72c6e2
fix welcome message test
zoran995 Nov 23, 2021
666e4b8
fix issue with welcome message
zoran995 Nov 24, 2021
748c591
Merge remote-tracking branch 'terriajs/main' into config-traits
zoran995 Apr 9, 2022
b9c607d
fix workflowPanel test
zoran995 Apr 9, 2022
53fcd2e
fix welcome-message test
zoran995 Apr 9, 2022
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
11 changes: 11 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,17 @@ Change Log
* Replace `CompositeBarItemController` `visible` setter with `setVisible` function
* Use `yarn` in CI scripts (and upgrade node to v14)
* Fix app crash when previewing a nested reference in the catalog (eg when viewing an indexed search result where the result is a reference).
* Converted terria ConfigParameters to model based approach.
* Some config parameters are depreacted (there is a basic conversion from old parameters to new ones):
* `showWelcomeMessage` and `welcomeMessageVideo` are now parameters on object `welcomeMessage` as `show` and `video`
* `helpContent` is now `helpItems`
* `helpContentTerms` are now `helpTerms`
* `feedbackPreamble` and `feedbackMinLength` are now parameters on object `feedback` as `preamble` and `minLength`
* `brandBarElements`, `brandBarSmallElements`, `displayOneBrand` are now parameters on object `brandBar` as `elements`, `smallElements`, `displayOneBrand`
* `googleUrlShortenerKey` is deprecated and not used anymore
* `disclaimer` is deprecated and not used anymore
* Removed deprecated configParameters from docs.
* [The next improvement]
* Ported feaure from v7 to set WMS layers property from the value of `LAYERS`, `layers` or `typeName` from query string of CKAN resource URL.

#### 8.1.4 - 2021-10-15
Expand Down
15 changes: 5 additions & 10 deletions buildprocess/ci-values.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,14 @@ terriamap:
cesiumIonAccessToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIxZDY5MDE1YS0yNGFlLTQ1MzctYWNkNy0wNDQ1YWNiNTM5MDIiLCJpZCI6Mjk5Miwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTUzODAzMzgyNn0.a2uTotdiHUo8FiHsO4MVNZ1KT5pOF0rb7CFdwbRAsOo"
useCesiumIonBingImagery: true
googleAnalyticsKey:
disclaimer:
text: "Disclaimer: This map must not be used for navigation or precise spatial analysis"
url: "https://terria.io"
developerAttribution:
text: "Terria"
link: "https://terria.io"
appName: "TerriaJS Continuous Integration"
brandBarElements: ["", "<a target=\"_blank\" href=\"http://terria.io\"><img src=\"images/terria_logo.png\" height=\"52\" title=\"Version: {{version}}\" /></a>", ""]
brandBar:
elements: ["", "<a target=\"_blank\" href=\"http://terria.io\"><img src=\"images/terria_logo.png\" height=\"52\" title=\"Version: {{version}}\" /></a>", ""]
supportEmail: "info@terria.io"
mobileDefaultViewerMode: "2d"
experimentalFeatures: true
feedbackUrl: "feedback"
helpContent:
feedback:
url: "feedback"
helpItems:
-
title: "Getting started with the map"
itemName: gettingstarted
Expand Down
13 changes: 11 additions & 2 deletions buildprocess/generateCatalogIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import MappableMixin from "../lib/ModelMixins/MappableMixin";
import ReferenceMixin from "../lib/ModelMixins/ReferenceMixin";
import CatalogGroup from "../lib/Models/Catalog/CatalogGroup";
import registerCatalogMembers from "../lib/Models/Catalog/registerCatalogMembers";
import CommonStrata from "../lib/Models/Definition/CommonStrata";
import hasTraits from "../lib/Models/Definition/hasTraits";
import { BaseModel } from "../lib/Models/Definition/Model";
import { CatalogIndexFile } from "../lib/Models/SearchProviders/CatalogIndex";
Expand Down Expand Up @@ -268,8 +269,16 @@ export default async function generateCatalogIndex(
registerCatalogMembers();

try {
terria.configParameters.serverConfigUrl = `${baseUrl}serverconfig`;
terria.configParameters.corsProxyBaseUrl = `${baseUrl}proxy/`;
terria.configParameters.setTrait(
CommonStrata.user,
"serverConfigUrl",
`${baseUrl}serverconfig`
);
terria.configParameters.setTrait(
CommonStrata.user,
"corsProxyBaseUrl",
`${baseUrl}proxy/`
);
await terria.start({ configUrl });

await terria.loadInitSources();
Expand Down
54 changes: 42 additions & 12 deletions doc/customizing/client-side-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ Specifies various options for configuring TerriaJS:
|`useCesiumIonBingImagery`|no|**boolean**|`true`|True to use Bing Maps from Cesium ion (Cesium World Imagery). By default, Ion will be used, unless the `bingMapsKey` property is specified, in which case that will be used instead. To disable the Bing Maps layers entirely, set this property to false and set `bingMapsKey` to null.|
|`bingMapsKey`|no|**string**|undefined|A [Bing Maps API key](https://msdn.microsoft.com/en-us/library/ff428642.aspx) used for requesting Bing Maps base maps and using the Bing Maps geocoder for searching. It is your responsibility to request a key and comply with all terms and conditions.|
|`hideTerriaLogo`|no|**boolean**|`false`|
|`brandBarElements`|no|**string[]**|undefined|An array of strings of HTML that fill up the top left logo space (see `brandBarSmallElements` or `displayOneBrand` for small screens).|
|`brandBarSmallElements`|no|**string[]**|undefined|An array of strings of HTML that fill up the top left logo space - used for small screens.|
|`displayOneBrand`|no|**number**|`0`|Index of which `brandBarElements` to show for mobile header. This will only be used if `brandBarSmallElements` is undefined.|
|`brandBar`|no|**[BrandBar](#brandbar)|`new BrandBarTraits()`|Branding bar configuration|
|`disableMyLocation`|no|**boolean**|undefined|True to disable the "Centre map at your current location" button.|
|`disableSplitter`|no|**boolean**|undefined|True to disable the use of the splitter control.|
|`experimentalFeatures`|no|**boolean**|undefined||
Expand All @@ -75,18 +73,15 @@ Specifies various options for configuring TerriaJS:
|`googleAnalyticsKey`|no|**string**|undefined|A Google API key for [Google Analytics](https://analytics.google.com). If specified, TerriaJS will send various events about how it's used to Google Analytics.|
|`errorService`|no|**[ErrorServiceOptions](#errorserviceoptions)**|undefined|Optional configuration for the remote error logging service that Terria should log errors to.|
|`globalDisclaimer`|no|**any**|undefined||
|`showWelcomeMessage`|no|**boolean**|`false`|True to display welcome message on startup.|
|`welcomeMessageVideo`|no|**any**||Video to show in welcome message.|
|`welcomeMessage`|no|**[WelcomeMessage](#welcomemessage)**|`false`||
|`showInAppGuides`|no|**boolean**|`false`|True to display in-app guides.|
|`helpContent`|no|**[HelpContentItem](#helpcontentitem)**|`[]`|The content to be displayed in the help panel.|
|`helpContentTerms`|no|**[Term](#term)**|||
|`helpItems`|no|**[HelpItem](#helpitem)**|`[]`|The content to be displayed in the help panel.|
|`helpTerms`|no|**[Term](#term)**|||
|`languageConfiguration`|no|**[LanguageConfiguration](#languageconfiguration)**|undefined|Language configuration of TerriaJS.|
|`customRequestSchedulerLimits`|no|**[RequestScheduler](https://cesium.com/docs/cesiumjs-ref-doc/RequestScheduler.html#.requestsByServer)**|undefined|Custom concurrent request limits for domains in Cesium's RequestScheduler.|
|`persistViewerMode`|no|**boolean**|`true`|Whether to load persisted viewer mode from local storage.|
|`openAddData`|no|**boolean**|`false`|Whether to open the add data explorer panel on load.|
|feedbackPreamble|no|**string**|feedback.feedbackPreamble|Text showing at the top of feedback form, supports the internationalization using the translation key.|
|feedbackPostamble|no|**string**|feedback.feedbackPostamble|Text showing at the bottom of feedback form, supports the internationalization using the translation key.|
|feedbackMinLength|no|**number**|0|Minimum length of feedback comment.|
|`feedback`|no|**[Feedback](#feedback)**||Feedback configuration.|
|`theme`|no|**any**|`{}`|An object used to override theme properties - for example `{"logoHeight": "70px"}`.|
|`storyRouteUrlPrefix`|no|**string**|undefined|(Experimental) Prefix to which `:story-id` is added to fetch JSON for stories when using `/story/:story-id` routes. Should end in /|

Expand All @@ -95,7 +90,32 @@ Specifies various options for configuring TerriaJS:

***

### HelpContentItem
### BrandBar
Branding bar configuration

|Name|Required|Type|Default|Description|
|----|--------|----|-------|-----------|
|`elements`|no|**string[]**|undefined|An array of strings of HTML that fill up the top left logo space (see `smallElements` or `displayOneBrand` for small screens).|
|`smallElements`|no|**string[]**|undefined|An array of strings of HTML that fill up the top left logo space - used for small screens.|
|`displayOneBrand`|no|**number**|`0`|Index of which `elements` to show for mobile header. This will only be used if `smallElements` is undefined.|

### WelcomeMessage
Welcome message configuration

|Name|Required|Type|Default|Description|
|----|--------|----|-------|-----------|
|`show`|yes|**boolean**|false|True to display welcome message on startup.|
|`video`|yes|**[WelcomeMessageVideo](#welcomemessagevideo) to show in welcome message.|

#### WelcomeMessageVideo

|Name|Required|Type|Default|Description|
|----|--------|----|-------|-----------|
|`title`|yes|**string**|undefined|Title of the video|
|`url`|yes|**string**|undefined|Url of the video|
|`placeholderImage`|yes|**string**|undefined|Placeholder image.|

### HelpItem
Configuration of items to appear in the search bar

|Name|Required|Type|Default|Description|
Expand All @@ -104,10 +124,11 @@ Configuration of items to appear in the search bar
|`title`|no|**string**|undefined|Title of the help item|
|`videoUrl`|no|**string**|undefined|The video to show on the top of help item.|
|`placeholderImage`|no|**string**|undefined|Placeholder image for the video.|
|`paneMode`|no|**enum["videoAndContent","slider","trainer"]**|`"videoAndContent"`|
|`paneMode`|no|**enum["videoAndContent","slider","trainer", "externalLink"]**|`"videoAndContent"`|
|`trainerItems`|no|**[TrainerItem[]](#traineritem)**|undefined|List of the trainer steps|
|`markdownText`|no|**string**|undefined|The content of the help item, can use Markdown syntax.|
|`icon`|no|**string**|undefined|Icon to show next to the itemName.|
|`url|no|**string**|undefined|External url for the help content item.|

#### TrainerItem

Expand Down Expand Up @@ -148,7 +169,16 @@ Configuration of items to appear in the search bar

***

### Feedback

|Name|Required|Type|Default|Description|
|----|--------|----|-------|-----------|
|`preamble`|no|**string**|`translate#feedback.feedbackPreamble`|Text showing at the top of feedback form, supports the internationalization using the translation key.|
|`postamble`|no|**string**|`undefined`|Text showing at the bottom of feedback form, supports the internationalization using the translation key.|
|`minLength`|no|**number**|0|Minimum length of feedback comment.|

### ErrorServiceOptions

|Name|Required|Type|Default|Description|
|----|--------|----|-------|-----------|
|provider|yes|**string**|`undefined`|A string identifying the error service provider to use. Currently only `rollbar` is supported.|
Expand Down
4 changes: 2 additions & 2 deletions doc/customizing/translation-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ This section describes how to use i18next to provide a translation of TerriaJS.

### Translation of configurable elements

To translate configurable elements, the value itself must be formatted correctly (it is called a translation key). The formatted value must then be added to the translation files with the corresponding translation. If the part of the config.json is considered for translations by the TerriaJS, the translation will take place. Elements that are available for translation are `helpContent`, and `helpContentTerms`.
To translate configurable elements, the value itself must be formatted correctly (it is called a translation key). The formatted value must then be added to the translation files with the corresponding translation. If the part of the config.json is considered for translations by the TerriaJS, the translation will take place. Elements that are available for translation are `helpItems`, and `helpTerms`.
The translation key must be prefixed with `"translate#"`, so the structure of the key is `translate#[path.to.key]`, resulting in e.g. `translate#help.gettingstarted.content`

**Translation file**
Expand All @@ -66,7 +66,7 @@ The translation key must be prefixed with `"translate#"`, so the structure of th

**Translateable content**
```json
"helpContent": [
"helpItems": [
{
"title": "translate#help.gettingstarted.title",
"itemName": "gettingstarted",
Expand Down
8 changes: 4 additions & 4 deletions lib/Core/injectTerms.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Term } from "../ReactViewModels/defaultTerms";
import i18next from "i18next";
import { useTranslationIfExists } from "../Language/languageHelpers";
import { TermTraits } from "../Traits/Configuration/TermTraits";

const findFirstTerm = (
text: string,
terms: Map<string, Term>,
terms: Map<string, TermTraits>,
fromIndex: number
) => {
let termIndex = Infinity;
Expand Down Expand Up @@ -68,11 +68,11 @@ const findFirstTerm = (
return { termToReplace, termIndex, ignore };
};

const injectTerms = (string: string, termDictionary: Term[]): string => {
const injectTerms = (string: string, termDictionary: TermTraits[]): string => {
let injectIndex = 0;
const injectedBoldSet = new Set();
while (1) {
let tooltipTerms = new Map<string, Term>();
let tooltipTerms = new Map<string, TermTraits>();

termDictionary.forEach((item: any) =>
tooltipTerms.set(useTranslationIfExists(item.term).toLowerCase(), item)
Expand Down
4 changes: 2 additions & 2 deletions lib/Core/markdownToHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
var defined = require("terriajs-cesium/Source/Core/defined").default;
var MarkdownIt = require("markdown-it");
var DOMPurify = require("dompurify/dist/purify");
import { TermTraits } from "../Traits/Configuration/TermTraits";
import injectTerms from "./injectTerms";
import { Term } from "../ReactViewModels/defaultTerms";

var md = new MarkdownIt({
html: true,
Expand All @@ -18,7 +18,7 @@ export interface MarkdownOptions {
injectTermsAsTooltips?: boolean;

// requires injectTermsAsTooltips as well
tooltipTerms?: Term[];
tooltipTerms?: TermTraits[];

/** Single line rendering, without paragraph wrap */
inline?: boolean;
Expand Down
2 changes: 2 additions & 0 deletions lib/Language/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,8 @@
},
"terria": {
"loadConfigErrorTitle": "Failed to load Terria Map config",
"loadConfigErrorMessage": "Couldn't load {{configUrl}}",
"parseConfigErrorMessage": "Config loaded from {{configUrl}} is invalid",
"proxyableDomainsDeprecation": "`proxyableDomainsUrl` is no longer supported in v8",
"initErrorTitle": "Failed to initialize services",
"initErrorMessage": "A problem occurred with the Terria server. This may cause some layers or the conversion service to be unavailable.",
Expand Down
18 changes: 10 additions & 8 deletions lib/Models/BaseMaps/BaseMapsModel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { action, computed } from "mobx";
import { action, computed, runInAction } from "mobx";
import DeveloperError from "terriajs-cesium/Source/Core/DeveloperError";
import isDefined from "../../Core/isDefined";
import Result from "../../Core/Result";
Expand Down Expand Up @@ -117,11 +117,13 @@ export class BaseMapsModel extends CreateModel(BaseMapsTraits) {
}

function addBingMapsKey(item: BingMapsCatalogItem, terria: Terria) {
if (!item.key) {
item.setTrait(
CommonStrata.defaults,
"key",
terria.configParameters.bingMapsKey
);
}
runInAction(() => {
if (!item.key && terria.configParameters.bingMapsKey !== null) {
item.setTrait(
CommonStrata.defaults,
"key",
terria.configParameters.bingMapsKey
);
}
});
}
12 changes: 7 additions & 5 deletions lib/Models/BaseMaps/defaultBaseMaps.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { runInAction } from "mobx";
import Terria from "../Terria";

export function defaultBaseMaps(terria: Terria): any[] {
const baseMaps: any[] = [];
const bingMapsKey = runInAction(() => terria.configParameters.bingMapsKey);
const useCesiumIonBingImagery = runInAction(
() => terria.configParameters.useCesiumIonBingImagery
);

if (
terria.configParameters.bingMapsKey &&
!terria.configParameters.useCesiumIonBingImagery
) {
if (bingMapsKey && !useCesiumIonBingImagery) {
baseMaps.push({
item: {
id: "basemap-bing-aerial-with-labels",
Expand Down Expand Up @@ -41,7 +43,7 @@ export function defaultBaseMaps(terria: Terria): any[] {
image: "build/TerriaJS/images/bing-maps-roads.png",
contrastColor: "#000000"
});
} else if (terria.configParameters.useCesiumIonBingImagery === true) {
} else if (useCesiumIonBingImagery === true) {
baseMaps.push({
item: {
id: "basemap-bing-aerial-with-labels",
Expand Down
1 change: 1 addition & 0 deletions lib/Models/Catalog/CatalogItems/GpxCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import UrlMixin from "../../../ModelMixins/UrlMixin";
import GpxCatalogItemTraits from "../../../Traits/TraitsClasses/GpxCatalogItemTraits";
import CreateModel from "../../Definition/CreateModel";
import proxyCatalogItemUrl from "../proxyCatalogItemUrl";
import GeoJsonCatalogItem from "./GeoJsonCatalogItem";

const toGeoJSON = require("@mapbox/togeojson");

Expand Down
2 changes: 1 addition & 1 deletion lib/Models/Catalog/CatalogItems/KmlCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import Property from "terriajs-cesium/Source/DataSources/Property";
import isDefined from "../../../Core/isDefined";
import readXml from "../../../Core/readXml";
import TerriaError, { networkRequestError } from "../../../Core/TerriaError";
import MappableMixin from "../../../ModelMixins/MappableMixin";
import CatalogMemberMixin from "../../../ModelMixins/CatalogMemberMixin";
import MappableMixin from "../../../ModelMixins/MappableMixin";
import UrlMixin from "../../../ModelMixins/UrlMixin";
import KmlCatalogItemTraits from "../../../Traits/TraitsClasses/KmlCatalogItemTraits";
import CreateModel from "../../Definition/CreateModel";
Expand Down
8 changes: 4 additions & 4 deletions lib/Models/Catalog/createCatalogItemFromFileOrUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import i18next from "i18next";
import { runInAction } from "mobx";
import isDefined from "../../Core/isDefined";
import TerriaError from "../../Core/TerriaError";
import ReferenceMixin from "../../ModelMixins/ReferenceMixin";
import ViewState from "../../ReactViewModels/ViewState";
import CatalogMemberFactory from "./CatalogMemberFactory";
import CommonStrata from "../Definition/CommonStrata";
import createUrlReferenceFromUrl from "./CatalogReferences/createUrlReferenceFromUrl";
import { BaseModel } from "../Definition/Model";
import Terria from "../Terria";
import upsertModelFromJson from "../Definition/upsertModelFromJson";
import ReferenceMixin from "../../ModelMixins/ReferenceMixin";
import Terria from "../Terria";
import CatalogMemberFactory from "./CatalogMemberFactory";
import createUrlReferenceFromUrl from "./CatalogReferences/createUrlReferenceFromUrl";

export default function createCatalogItemFromFileOrUrl(
terria: Terria,
Expand Down
2 changes: 1 addition & 1 deletion lib/Models/Cesium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export default class Cesium extends GlobeOrMap {
// The terrain server is not responding at the moment. You can still use all the features of '+that.terria.appName+' \
// but there will be no terrain detail in 3D mode. We\'re sorry for the inconvenience. Please try \
// again later and the terrain server should be responding as expected. If the issue persists, please contact \
// us via email at '+that.terria.supportEmail+'.'
// us via email at '+that.terria.configParameters.supportEmail+'.'
// });
// that.TerrainMessageViewed = true;
// }
Expand Down
Loading