Difference between revisions of "Codebase"

From Wikidocumentaries
Jump to navigation Jump to search
(state)
(Calls)
 
(37 intermediate revisions by the same user not shown)
Line 52: Line 52:
 
===state===
 
===state===
 
* wikidocumentariesDataState: WIKI.STATES.UNINITIALIZED,
 
* wikidocumentariesDataState: WIKI.STATES.UNINITIALIZED,
* wikidocumentaries: [[#wikidocumentaries]]
+
* wikidocumentaries: [[#wikidocumentaries|wikidocumentaries]]
 
* shownImages (array)
 
* shownImages (array)
 
* timelineImages (array)
 
* timelineImages (array)
 
* historicalMapSearchPageMap (array)
 
* historicalMapSearchPageMap (array)
 
* historicalMaps (array)
 
* historicalMaps (array)
* basemaps: [[#basemaps]]
+
* basemaps: [[#basemaps|basemaps]]
 
** selectedBasemaps (array)
 
** selectedBasemaps (array)
 
** selectedBasemapOpacity (float)
 
** selectedBasemapOpacity (float)
Line 69: Line 69:
 
** nearbyWikiItems (array)
 
** nearbyWikiItems (array)
  
==Data flow==
+
==Router==
In components e.g.
+
#
* method '''wikidocumentaries'''
+
#: path: '/dev'
** $store.state.wikidocumentaries
+
#: name: 'DevPage'
 +
#: component: devpage
 +
#
 +
#: path: '/'
 +
#: name: 'LandingPage'
 +
#: component: LandingPage
 +
#
 +
#: path: '/wikipedia/:'''language'''/:'''topic''''
 +
#: component: MainPage
 +
#
 +
#: path: '/:'''wikidata'''/:'''language'''?/:'''topic'''?'
 +
#: name: 'TopicPage'
 +
#: component: MainPage
  
store/store.js
+
==Wikidocumentaries-API==
 +
get
 +
=== /wiki ===
 +
app.get('/wiki', function(req, '''res''')
 +
* var '''language''' = req.query.language
 +
* var '''topic''' = req.query.topic
 +
* var '''wikidata''' = req.query.wikidata
 +
* var wikidataByItemIdPromise('''wikidata''') - ''Retrieve all data from Wikidata based on a QID''
 +
** var requestConfig
 +
*** baseURL: "https://www.wikidata.org/w/api.php"
 +
*** method: "get"
 +
*** responseType: 'json'
 +
*** headers: 'Api-User-Agent': process.env.WIKIDOCUMENTARIES_API_USER_AGENT
 +
*** params: action: "wbgetentities", ids: '''wikidata''', format: "json"
 +
** return axios.request(requestConfig).then((response) =>
 +
*** var '''item'''=response.data.entities['''wikidata''']
 +
*** combineResults('''res''', '''language''', '''wikidata''', '''item''')
 +
* var getWikidataItemIDPromise() - ''Get the QID based on a Wikipedia article name and language''
 +
** var requestConfig
 +
*** baseURL: "https://" + '''language''' + ".wikipedia.org/w/api.php"
 +
*** method: "get"
 +
*** responseType: 'json'
 +
*** headers: 'Api-User-Agent': process.env.WIKIDOCUMENTARIES_API_USER_AGENT
 +
*** params: action: "query", prop: "pageprops", ppprop: "wikibase_item", redirects: "resolve", titles: '''topic''', format: "json"
 +
** return axios.request(requestConfig).then((response) =>
 +
*** if (response.data.query != undefined)
 +
**** var key=Object.keys(response.data.query.pages)[0]
 +
**** var page=response.data.query.pages[key]
 +
**** if (page["pageprops"] != undefined && page["pageprops"]["wikibase_item"]!=undefined)
 +
***** wikidata=page["pageprops"]["wikibase_item"]
 +
***** wikidataByItemIdPromise(wikidata) - ''Loop back to make the Wikidata query''
  
<pre>
+
====Functions====
const wikidocumentaries = {
+
* combineResults('''res''', '''language''', wikidataItemID, wikidataItemResponse)
    title: 'Vapaamuurarin hauta',
+
** wikipediaSummaryPromise()
    description: 'Muistomerkki Helsingissä',
+
** wikipediaHTMLPromise()
    headerImageURL: 'https://upload.wikimedia.org/wikipedia/commons/b/bf/Helsinki_Kaisaniemi_Freemason%27s_grave_1908_I_K_Inha.png',
+
** axios.all([wikipediaSummaryPromise(), wikipediaHTMLPromise(), wikidataItemResponse ])
    wikipedia: {
+
*** .then(axios.spread(function (wikipediaSummaryResponse, wikipediaHTMLResponse, wikidataItemResponse )
        excerptHTML: null,
+
*** .then((responseData)
        remainingHTML: null,
+
* convertToWikidocumentariesHTML(origHTML, '''topic''', '''language''')
        wikipediaURL: 'https://fi.wikipedia.org/wiki/Vapaamuurarin_hauta'
+
* findLabel(entities, id, language)
    },
 
    wikidata: {
 
        id: 'Q5501061',
 
        instance_of: {
 
            id: 'Q5003624',
 
            value: 'muistomerkki',
 
            url: 'https://www.wikidata.org/wiki/Q5003624'
 
        },
 
        statements: [
 
            {
 
                id: 'P361',
 
                label: 'osa kohdetta',
 
                value: 'Kaisaniemen puisto ja kasvitieteellinen puutarha',
 
                url: 'https://www.wikidata.org/wiki/Q30506322'
 
            },
 
        dates: [],
 
    },
 
    images: [
 
        {
 
            id: 'musketti.M012:HK19670603:7117',
 
            source: 'finna',
 
            imageURL: "https://www.finna.fi/Cover/Show?id=musketti.M012:HK19670603:7117&index=0&size=large",
 
            title: "Vapaamuurarin hauta Kaisaniemessä",
 
            authors: "Pietinen",
 
            institutions: "Museovirasto",
 
            infoURL: "https://www.finna.fi/Record/musketti.M012:HK19670603:7117",
 
            location: "Helsinki,",
 
            geoLocations: ["POLYGON((24.7828131 60.0999549, 24.8356577 60.130414, 24.8513844 60.2249765, 24.8419098 60.2212043, 24.8347825 60.2585099, 24.8677628 60.2523073, 24.9473908 60.2784652, 24.9731653 60.2643801, 25.0209862 60.2893227, 25.0882105 60.2713417, 25.0823359 60.2496391, 25.1358461 60.2372286, 25.1598757 60.2488133, 25.1425242 60.2697779, 25.2545116 60.2952274, 25.2509121 60.2734979, 25.2273451 60.2611057, 25.240926 60.246305, 25.2014099 60.2181613, 25.2204176 60.1997262, 25.1800446 60.0987408, 25.1693516 59.9434386, 24.9423061 59.922486, 24.7828131 60.0999549))"],
 
            year: 1932,
 
            license: "CC BY 4.0"
 
        },
 
    ],
 
    geo: {
 
        location: "POINT(24.943752 60.176013)",
 
        admin: "Helsinki"
 
    },
 
    topicStartYear: 1784,
 
}
 
  
export default new Vuex.Store({
+
=== /wiki/items/by/latlon ===
    state: {
+
* var '''language''' = req.query.language;
        wikidocumentariesDataState: WIKI.STATES.UNINITIALIZED,
+
* var '''topic''' = req.query.topic;
        wikidocumentaries: wikidocumentaries,
+
* var requestConfig
        shownImages: [],
+
**baseURL: 'https://query.wikidata.org/'
        timelineImages: [],
+
** url: '/bigdata/namespace/wdq/sparql?query=SELECT%3Fitem(SAMPLE(%3Fitem_label)as%3Flabel)(SAMPLE(%3Flocation)as%3Flocation)WHERE%7BSERVICE%20wikibase%3Aaround%7B%3Fitem%20wdt%3AP625%3Flocation.bd%3AserviceParam%20wikibase%3Acenter"Point(' + req.query.lon + '%20' + req.query.lat + ')"%5E%5Egeo%3AwktLiteral.%20bd%3AserviceParam%20wikibase%3Aradius"' + req.query.radius / 1000 + '".%7DOPTIONAL%7B%3Fitem%20rdfs%3Alabel%3Fitem_label.%7D%7DGROUP%20BY%20%3Fitem'
        historicalMapSearchPageMap: null,
+
** timeout: 20000
        historicalMaps: [],
+
** method: "get"
        basemaps: basemaps,
+
**params: format: 'json'
        selectedBasemaps: [],
+
* Response: wikiItems.push for each response.data.results.bindings
        selectedBasemapOpacity: 0.7,
+
** id: id,
        shouldFitMapToBasemap: false,
+
** title: response.data.results.bindings[i].label.value,
        photoOfTheDay: "https://upload.wikimedia.org/wikipedia/commons/a/ad/Kulutusosuuskuntien_Keskusliiton_kokoelma_D1974_11333A_%2830804608561%29.jpg",
+
** lat: Number(lat)
        mapOfTheDay: {
+
** lon: Number(lon)
            id: "File:1900_Plan_af_Helsingfors_stad.tif",
 
            warperID: 148,
 
            server: "http://warper.wmflabs.org/",
 
            coordinates: [24.9351, 60.1658],
 
        },
 
        nearbyWikiItems: [],
 
    },
 
    getters: {
 
        topicStartYear: state => {
 
        }
 
    },
 
    mutations: {
 
        resetState(state) {
 
  
            state.wikidocumentariesDataState = WIKI.STATES.UNINITIALIZED;
+
=== /images ===
  
            state.wikidocumentaries = {
+
Parameters
                title: null,
+
* language
                description: null,
+
* topic
                headerImageURL: null,
+
* commons_category
                wikipedia: {
 
                    excerptHTML: null,
 
                    remainingHTML: null,
 
                    wikipediaURL: null,
 
                },
 
                wikidata: {
 
                    id: null,
 
                    instance_of: {
 
                        id: null,
 
                        value: null,
 
                        url: null
 
                    },
 
                    statements: [],
 
                    dates: [],
 
                },
 
                images: [],
 
                geo: {
 
                    location: null,
 
                    scale: null,
 
                    admin: null
 
                },
 
                topicStartYear: null
 
            };
 
            state.shownImages = [];
 
            state.timelineImages = [];
 
            state.historicalMapSearchPageMap = null;
 
            state.historicalMaps = [];
 
            state.basemaps = basemaps;
 
            state.selectedBasemaps = [];
 
            state.selectedBasemapOpacity = 0.7;
 
            state.shouldFitMapToBasemap = false;
 
            state.nearbyWikiItems = [];
 
        },
 
        setImagesShownOnMap(state, images) {
 
            state.shownImages = images;
 
        },
 
        setImagesShownOnTimeline(state, images) {
 
            state.timelineImages = images;
 
        },
 
        setHistoricalMapSearchPageMap(state, map) {
 
            state.historicalMapSearchPageMap = map;
 
        },
 
        setHistoricalMaps(state, maps) {
 
            state.historicalMaps = maps;
 
        },
 
        setSelectedBasemap(state, mapInfo) {
 
            state.selectedBasemaps = [mapInfo];
 
        },
 
        setSelectedBasemaps(state, mapInfos) {
 
            state.selectedBasemaps = mapInfos;
 
        },
 
        setSelectedBasemapOpacity(state, opacity) {
 
            state.selectedBasemapOpacity = opacity;
 
        },
 
        setShouldFitMapToBasemap(state, value) {
 
            state.shouldFitMapToBasemap = value;
 
        },
 
        setWikidocumentariesTopicTitle(state, title) {
 
            state.wikidocumentaries.title = title;
 
        },
 
        setWikidocumentariesTopicDescription(state, description) {
 
            state.wikidocumentaries.description = description;
 
        },
 
        setWikidata(state, wikidata) {
 
            state.wikidocumentaries.wikidata = wikidata;
 
        },
 
        setWikidataId(state, wikidataId) {
 
            state.wikidocumentaries.wikidataId = wikidataId;
 
        },
 
        setHeaderImageURL(state, URL) {
 
            state.wikidocumentaries.headerImageURL = URL;
 
        },
 
        setWikipediaExcerptHTML(state, html) {
 
            state.wikidocumentaries.wikipedia.excerptHTML = html;
 
        },
 
        setWikipediaRemainingHTML(state, html) {
 
            state.wikidocumentaries.wikipedia.remainingHTML = html;
 
        },
 
        setWikipediaURL(state, URL) {
 
            state.wikidocumentaries.wikipedia.wikipediaURL = URL;
 
        },
 
        setTopicGeoLocation(state, coordinates) {
 
            state.wikidocumentaries.geo.location = "POINT(" + coordinates.lon + " " + coordinates.lat + ")"
 
        },
 
        setWikidocumentariesDataState(state, value) {
 
            state.wikidocumentariesDataState = value;
 
        },
 
        setWikidocumentariesImages(state, images) {
 
            state.wikidocumentaries.images = images;
 
        },
 
        setTopicStartYear(state, year) {
 
            state.wikidocumentaries.topicStartYear = year;
 
        },
 
        setHistoricalBasemaps(state, basemaps) {
 
            state.basemaps = basemaps;
 
            if (basemaps.length > 0) {
 
                state.selectedBasemaps = [basemaps[0]];
 
            }
 
        },
 
        setNearbyWikiItems(state, items) {
 
            state.nearbyWikiItems = items;
 
        }
 
  
    },
+
Not in use
    actions: {
+
* lat
        updateWikidocumentaries({dispatch, commit}, params) {
+
* lon
        },
+
* maxradius
        async getWikiDocumentariesData(context, params) {
 
        },
 
        async getTopicImages({dispatch, commit}, params) {
 
        },
 
        async getHistoricalMaps({dispatch, commit}, locationParams) {
 
        },
 
        async getHistoricalMapsFromCommons(context, params) {
 
        },
 
        async getHistoricalMapsFromFinna(context, params) {
 
        },
 
        async getNearbyPlaces(context, params) {
 
        }
 
    }
 
});
 
  
function isWikidataBasedUnchangableStartYear(wikidocumentaries) {
+
====Called from====
}
 
  
function calculateTopicStartYearFromWikidata(wikidata, currentStartYear) {
+
====Calls====
}
 
  
function createGetCommonsMapInfoTask(fileName) {
+
=== /basemaps ===
}
+
=== /geocode ===
</pre>
 

Latest revision as of 10:04, 12 February 2019

Navigate the codebase

Global variables

wikidocumentaries

Reads all values at time of page load from Wikipedia and Wikidata and prepares for the app. Stored, updated add addressed at @/store/store.js

  • title - Wikidata title in the user's language. Add a fallback option and create a new property with knowledge about the original value (boolean exists or empty data).
  • description - Wikidata title in the user's language. Add a fallback option and create a new property with knowledge about the original value (boolean exists or empty data).
  • headerImageURL
  • wikipedia
    • excerptHTML - summary part of the Wikipedia article
    • remainingHTML - remaining part of the Wikipedia article as a separate object.
    • wikipediaURL - link to the Wikipedia article in the user's language
  • wikidata
    • id
    • instance_of
      • id
      • value
      • url
    • statements
      • id
      • label
      • value - This returns a string for an object, and the QID is only in the URL. The QID should be extracted already before this?
      • url
      • dates
  • images
    • id
    • source
    • imageURL
    • title
    • authors
    • institutions
    • infoURL
    • location
    • geoLocations
    • year
    • license
  • geo
    • location
    • admin
  • topicStartYear

basemaps

  • id
  • title
  • imageURL
  • year
  • server
  • warperID
  • municipality
  • country

state

Router

  1. path: '/dev'
    name: 'DevPage'
    component: devpage
  2. path: '/'
    name: 'LandingPage'
    component: LandingPage
  3. path: '/wikipedia/:language/:topic'
    component: MainPage
  4. path: '/:wikidata/:language?/:topic?'
    name: 'TopicPage'
    component: MainPage

Wikidocumentaries-API

get

/wiki

app.get('/wiki', function(req, res)

  • var language = req.query.language
  • var topic = req.query.topic
  • var wikidata = req.query.wikidata
  • var wikidataByItemIdPromise(wikidata) - Retrieve all data from Wikidata based on a QID
    • var requestConfig
      • baseURL: "https://www.wikidata.org/w/api.php"
      • method: "get"
      • responseType: 'json'
      • headers: 'Api-User-Agent': process.env.WIKIDOCUMENTARIES_API_USER_AGENT
      • params: action: "wbgetentities", ids: wikidata, format: "json"
    • return axios.request(requestConfig).then((response) =>
      • var item=response.data.entities[wikidata]
      • combineResults(res, language, wikidata, item)
  • var getWikidataItemIDPromise() - Get the QID based on a Wikipedia article name and language
    • var requestConfig
      • baseURL: "https://" + language + ".wikipedia.org/w/api.php"
      • method: "get"
      • responseType: 'json'
      • headers: 'Api-User-Agent': process.env.WIKIDOCUMENTARIES_API_USER_AGENT
      • params: action: "query", prop: "pageprops", ppprop: "wikibase_item", redirects: "resolve", titles: topic, format: "json"
    • return axios.request(requestConfig).then((response) =>
      • if (response.data.query != undefined)
        • var key=Object.keys(response.data.query.pages)[0]
        • var page=response.data.query.pages[key]
        • if (page["pageprops"] != undefined && page["pageprops"]["wikibase_item"]!=undefined)
          • wikidata=page["pageprops"]["wikibase_item"]
          • wikidataByItemIdPromise(wikidata) - Loop back to make the Wikidata query

Functions

  • combineResults(res, language, wikidataItemID, wikidataItemResponse)
    • wikipediaSummaryPromise()
    • wikipediaHTMLPromise()
    • axios.all([wikipediaSummaryPromise(), wikipediaHTMLPromise(), wikidataItemResponse ])
      • .then(axios.spread(function (wikipediaSummaryResponse, wikipediaHTMLResponse, wikidataItemResponse )
      • .then((responseData)
  • convertToWikidocumentariesHTML(origHTML, topic, language)
  • findLabel(entities, id, language)

/wiki/items/by/latlon

  • var language = req.query.language;
  • var topic = req.query.topic;
  • var requestConfig
    • baseURL: 'https://query.wikidata.org/'
    • url: '/bigdata/namespace/wdq/sparql?query=SELECT%3Fitem(SAMPLE(%3Fitem_label)as%3Flabel)(SAMPLE(%3Flocation)as%3Flocation)WHERE%7BSERVICE%20wikibase%3Aaround%7B%3Fitem%20wdt%3AP625%3Flocation.bd%3AserviceParam%20wikibase%3Acenter"Point(' + req.query.lon + '%20' + req.query.lat + ')"%5E%5Egeo%3AwktLiteral.%20bd%3AserviceParam%20wikibase%3Aradius"' + req.query.radius / 1000 + '".%7DOPTIONAL%7B%3Fitem%20rdfs%3Alabel%3Fitem_label.%7D%7DGROUP%20BY%20%3Fitem'
    • timeout: 20000
    • method: "get"
    • params: format: 'json'
  • Response: wikiItems.push for each response.data.results.bindings
    • id: id,
    • title: response.data.results.bindings[i].label.value,
    • lat: Number(lat)
    • lon: Number(lon)

/images

Parameters

  • language
  • topic
  • commons_category

Not in use

  • lat
  • lon
  • maxradius

Called from

Calls

/basemaps

/geocode