Demo VisualData 1.0 / Dependent values

Dependent values: Difference between revisions

From Wikisphere
Jump to navigation Jump to search
(Created page with " {{#pagepropertiesform: Dependent values |title = Dependent values |action = create |edit-page = |return-page = |view = inline |popup-size = medium |css-class = |pagename-formula = |edit-freetext = false |edit-categories = false |edit-content-model = false |default-categories = tasks |default-content-model = json |layout-align = top |popup-help = true |submit-button-text = |layout = tabs |submit-button-text = |validate-button-text = }}")
 
No edit summary
Tag: 2017 source edit
 
(30 intermediate revisions by the same user not shown)
Line 1: Line 1:
The following form demonstrates the use of VisualData to query and record dependent values (the classical case is the country-state-city relationship) and to easily create and store them on your wiki through a couple of maintenance scripts. It uses the schema [[VisualDataSchema:Dependent_values]] created through the Schema Builder (see special page [[Special:ManageSchemas]] then open the schema "Dependent values").


{{#pagepropertiesform: Dependent values
 
{{#visualdataform: Dependent values
|title = Dependent values
|title = Dependent values
|action = create
|action = create
Line 12: Line 15:
|edit-categories = false
|edit-categories = false
|edit-content-model = false
|edit-content-model = false
|default-categories = tasks
|default-categories =  
|default-content-model = json
|default-content-model = json
|layout-align = top
|layout-align = top
Line 21: Line 24:
|validate-button-text =
|validate-button-text =
}}
}}
The first field (country) is a OOUI DropdownInputWidget with items taken from the template [[Template:Countries]].
The second field (state) is a LookupElement with query
<pre>
[[name::<country>]][[states/name::<value>~]]
</pre>
where <code><nowiki><country></nowiki></code> is the name of the first field and <code><nowiki><value></nowiki></code> is the value being inserted in the input.<!-- Note that the field names if nested have to be expressed using a path, for instance -->. The requested printout is <code>states/name</code> that matches the path <code>properties/states/items/properties/name</code> in the schema [[VisualDataSchema:Country]]. (where only relevant property names have to be concatenated, leaving aside <code>properties</code> and <code>items</code> that belong to the schema structure). The query will search json data related to the schema "Country" with value of the property <code>name</code> equal to the value of the first field, and value of the property <code>states/name</code> equal to the state input value.
The third field (city) uses this query
<pre>
[[name::<country>]][[states/name::<state>]][[states/cities/name::<value>~]]
</pre>
The query as above will search json data related to the schema "Country" with value of the property <code>name</code> equal to the value of the first field, value of the property <code>states/name</code> equal to the second field, and value of the property <code>states/cities/name</code> equal to the city input value. The requested printout in this case is <code>states/cities/name</code>.
'''The query searches within a database of [[Data:Countries|250 wiki pages]] with json content model like [[Data:Countries/Afghanistan]], containing more than 620,000 entries in total.'''
The database can been created downloading this data [https://github.com/dr5hn/countries-states-cities-database/blob/master/countries%2Bstates%2Bcities.json countries%2Bstates%2Bcities.json] from [https://github.com/dr5hn/countries-states-cities-database github.com/dr5hn/countries-states-cities-database] and then importing them on your wiki using the following maintenance command:
<pre>
php extensions/VisualData/maintenance/ImportData.php --file "[path-to-the following-file]/countries+states+cities.json" --schema Country --pagename-formula "Data:countries/<name>" --main-slot
</pre>
The script takes only a few minutes to create all the required entries (including the related schema if it does not exist) and the data can be rebuilt any time through the following command:
<pre>
php extensions/VisualData/maintenance/RebuildData.php
</pre>
This is the wikitext used to create the form itself:
<pre>
{{#visualdataform: Dependent values
|title = Dependent values
|action = create
|edit-page =
|return-page =
|view = inline
|popup-size = medium
|css-class =
|pagename-formula =
|edit-freetext = false
|edit-categories = false
|edit-content-model = false
|default-categories =
|default-content-model = json
|layout-align = top
|popup-help = true
|submit-button-text =
|layout = tabs
|submit-button-text =
|validate-button-text =
}}
</pre>
Have fun using your wiki as an open-source database management system !!
== See also ==
{{Demo VisualData footer}}

Latest revision as of 11:49, 4 February 2024

The following form demonstrates the use of VisualData to query and record dependent values (the classical case is the country-state-city relationship) and to easily create and store them on your wiki through a couple of maintenance scripts. It uses the schema VisualDataSchema:Dependent_values created through the Schema Builder (see special page Special:ManageSchemas then open the schema "Dependent values").


form is loading...


The first field (country) is a OOUI DropdownInputWidget with items taken from the template Template:Countries.

The second field (state) is a LookupElement with query

[[name::<country>]][[states/name::<value>~]]

where <country> is the name of the first field and <value> is the value being inserted in the input.. The requested printout is states/name that matches the path properties/states/items/properties/name in the schema VisualDataSchema:Country. (where only relevant property names have to be concatenated, leaving aside properties and items that belong to the schema structure). The query will search json data related to the schema "Country" with value of the property name equal to the value of the first field, and value of the property states/name equal to the state input value.

The third field (city) uses this query

[[name::<country>]][[states/name::<state>]][[states/cities/name::<value>~]]

The query as above will search json data related to the schema "Country" with value of the property name equal to the value of the first field, value of the property states/name equal to the second field, and value of the property states/cities/name equal to the city input value. The requested printout in this case is states/cities/name.


The query searches within a database of 250 wiki pages with json content model like Data:Countries/Afghanistan, containing more than 620,000 entries in total.

The database can been created downloading this data countries%2Bstates%2Bcities.json from github.com/dr5hn/countries-states-cities-database and then importing them on your wiki using the following maintenance command:

php extensions/VisualData/maintenance/ImportData.php --file "[path-to-the following-file]/countries+states+cities.json" --schema Country --pagename-formula "Data:countries/<name>" --main-slot

The script takes only a few minutes to create all the required entries (including the related schema if it does not exist) and the data can be rebuilt any time through the following command:

php extensions/VisualData/maintenance/RebuildData.php


This is the wikitext used to create the form itself:


{{#visualdataform: Dependent values
|title = Dependent values
|action = create
|edit-page = 
|return-page = 
|view = inline
|popup-size = medium
|css-class =
|pagename-formula = 
|edit-freetext = false
|edit-categories = false
|edit-content-model = false
|default-categories =
|default-content-model = json
|layout-align = top
|popup-help = true 
|submit-button-text =
|layout = tabs
|submit-button-text =
|validate-button-text =
}}


Have fun using your wiki as an open-source database management system !!


See also[edit | edit source]