Forráskód Böngészése

+ btn fetch more Krs Person if more then 10

Piotr Labudda 6 éve
szülő
commit
62db643b4e
1 módosított fájl, 70 hozzáadás és 5 törlés
  1. 70 5
      tools/Bocian.php.addItemToRaport.js

+ 70 - 5
tools/Bocian.php.addItemToRaport.js

@@ -76,6 +76,11 @@ function convertXlinkToObjects(items) {
         if (1 === Object.keys(child).length && 'xlink' in child) {
           var pk = child['xlink'].split('.').pop();
           return _childCache[fieldName][pk];
+        } else if ('p5:links' in child && 'p5:next' in child['p5:links']) {
+          return Object.assign({}, child['p5:links']['p5:next'], {
+            type: 'p5:next'
+          });
+          // child.value = "https://.../SE/wfs-data.php/?SERVICE=WFS&VERSION=1.0.0&TYPENAME=default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person&REQUEST=GetFeature&backRefNS=default_db/BI_audit_KRS/BI_audit_KRS&backRefPK=1332604&backRefField=default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person&maxFeatures=10&startIndex=10"
         }
         return child;
       })
@@ -136,16 +141,39 @@ var P5UI_AddItemToReport_SelectKrsPerson = createReactClass({
   //       "nazwisko": "WIECZORKOWSKA",
   //       "pesel": "75090401549"
   //     },
+  //    ...
+  //     {
+  //       "@backRefNS: "default_db/BI_audit_KRS/BI_audit_KRS"
+  //       @backRefPK: "1332604"
+  //       @maxFeatures: 10
+  //       @startIndex: 10
+  //       @typeName: "default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person"
+  //       type: "p5:next"
+  //       value: "https://biuro.biall-net.pl/dev-pl/se-projects/bocian/SE/wfs-data.php/?SERVICE=WFS&VERSION=1.0.0&TYPENAME=default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person&REQUEST=GetFeature&backRefNS=default_db/BI_audit_KRS/BI_audit_KRS&backRefPK=1332604&backRefField=default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person&maxFeatures=10&startIndex=10"
+  //     }
+  getKrsPersonsFromProps: function () {
+    return (this.props.krs && this.props.krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'])
+      ? this.props.krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person']
+      : [];
+  },
+  handleFetchMore: function () {
+    this.props.fetchMoreKrsPerson(this.props.krs);
+  },
   render: function () {
-    var krsPresons = (this.props.krs && this.props.krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'])
-    ? this.props.krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person']
-    : [];
+    var krsPresons = this.getKrsPersonsFromProps();
     // var _selectPerson = this.props.selectPerson.bind(this)
     var selectedBaza = 'default_db/BI_audit_KRS_person/BI_audit_KRS_person';
 
+    var handleFetchMore = this.handleFetchMore.bind(this);
+
     return (krsPresons.length > 0)
     ? h('ol', { style: { margin: '22px', textAlign: 'left' } }, krsPresons.map(function (person) {
       var label = (person.imiona || '') + ' ' + (person.nazwisko || '') + ', ' + (person.pesel || '');
+      if ('type' in person && "p5:next" == person['type']) {
+        return h('li', {}, [
+          h('a', { className: "btn btn-link", onClick: handleFetchMore }, "pobierz więcej ...")
+        ]);
+      }
       return h('li', {}, [
         h(P5UI_AddItemToReport_Checkbox, { from: 'OD', selectedBaza: selectedBaza, selectedItem: person }),
         h(P5UI_AddItemToReport_Checkbox, { from: 'DO', selectedBaza: selectedBaza, selectedItem: person }),
@@ -285,11 +313,46 @@ var P5UI_AddItemToReport = createReactClass({
     _handleSelected: function (selected) {
         this.setState({ selected: (selected.length > 0) ? selected[0] : null });
     },
+    _fetchMoreKrsPerson: function (krs) {
+      var _addMoreKrsPersons = this._addMoreKrsPersons.bind(this);
+      var pk = krs['@primaryKey']
+      var krsPersons = (krs && krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'])
+        ? krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person']
+        : [];
+      var lastPerson = krsPersons[ krsPersons.length - 1 ];
+      if (lastPerson && 'type' in lastPerson && "p5:next" == lastPerson['type']) {
+        var fetchNextLink = lastPerson['value'];
+        DBG && console.log("DBG: fetchNextLink", { fetchNextLink });
+        var cols = [ 'ID', 'imiona', 'nazwisko', 'pesel' ];
+        p5WFS_GetFeature(lastPerson['@typeName'], {
+          'p5:next': fetchNextLink.replace('&maxFeatures=10', '&maxFeatures=100') + '&' + 'propertyName=' + cols.join(',')
+        }).then(function (results) {
+          DBG && console.log('DBG: _fetchMoreKrsPerson result', { results });
+          _addMoreKrsPersons(pk, results.map(function (item) { return Object.assign({}, item, { '@primaryKey': item['ID'] }) }));
+        })
+      } else {
+        DBG && console.log("DBG: missing fetch more link");
+        return;
+      }
+    },
+    _addMoreKrsPersons: function (pk, moreKrsPersons) {
+      var newOptions = this.state.options.map(function (item) {
+        if (item['@primaryKey'] === pk) {
+          item['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'].pop() // rm last link node - p5:link/p5:next
+          return Object.assign(item, {
+            'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person': item['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'].concat(moreKrsPersons)
+          })
+        }
+        return item;
+      });
+      this.setState({
+        options: newOptions
+      })
+    },
     _handleSearch: function (query) {
         this.setState({ isSearching: true });
         var _setState = this.setState.bind(this);
         var baza = this.state.baza;
-        var options= [];
         window.fetch(URL_FETCH_FROM_BAZA, {
 					method: 'POST',
 					header: {
@@ -409,6 +472,7 @@ var P5UI_AddItemToReport = createReactClass({
         var handleSearch = this._handleSearch.bind(this);
         var handleSelected = this._handleSelected.bind(this);
         var _onSelect = this.props.onSelect;
+        var _fetchMoreKrsPerson = this._fetchMoreKrsPerson.bind(this);
         DBG && console.log('DBG: render this.state.options', this.state.options);
         return h('div', {}, [
             h('p', { style: { textAlign: "center" } }, "Wybierz bazę"),
@@ -667,7 +731,8 @@ var P5UI_AddItemToReport = createReactClass({
                 _onSelect("default_db/BI_audit_KRS_person/BI_audit_KRS_person", person);
                 // ReactDOM.unmountComponentAtNode(document.getElementById(FUNCTION_NAME + '__searchBaza'));
                 // swal.close()
-              }
+              },
+              fetchMoreKrsPerson: _fetchMoreKrsPerson
             }),
             ('default_db/BI_audit_MSIG/BI_audit_MSIG' === selectedBaza && selectedItem) && h(P5UI_AddItemToReport_SelectMSIGPerson, {
               msig: selectedItem,