فهرست منبع

updated search, fixed Nowa osoba form

Piotr Labudda 7 سال پیش
والد
کامیت
3b74ff13cd
2فایلهای تغییر یافته به همراه103 افزوده شده و 74 حذف شده
  1. 43 5
      tools/Bocian.php
  2. 60 69
      tools/Bocian.php.addItemToRaport.js

+ 43 - 5
tools/Bocian.php

@@ -922,8 +922,31 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 		Response::sendTryCatchJson(array($this, 'fetchFromBazaAjax'), $args = 'JSON_FROM_REQUEST_BODY');
 	}
 	public function fetchFromBazaAjax($args) {
-		$baza= V::get('baza', 1, $args);
-		$items = ACL::getAclByNamespace('default_db/BI_audit_KRS/BI_audit_KRS')->buildQuery([
+		$baza = V::get('baza', '', $args);
+		$query = V::get('query', '', $args);
+		if (strlen($query) < 3) throw new Exception("Query must be more then 2 chars");
+
+		$ogcSearch = "*{$query}*";
+		$searchParams = [];
+		$searchParams['ogc:Filter'] = '
+			<ogc:Filter>
+				<ogc:Or>
+					<ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
+						<ogc:PropertyName>nazwa</ogc:PropertyName>
+						<ogc:Literal>' . $ogcSearch . '</ogc:Literal>
+					</ogc:PropertyIsLike>
+					<ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
+						<ogc:PropertyName>nip</ogc:PropertyName>
+						<ogc:Literal>' . $ogcSearch . '</ogc:Literal>
+					</ogc:PropertyIsLike>
+					<ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
+						<ogc:PropertyName>S_miejscowosc</ogc:PropertyName>
+						<ogc:Literal>' . $ogcSearch . '</ogc:Literal>
+					</ogc:PropertyIsLike>
+				</ogc:Or>
+			</ogc:Filter>
+		';
+		$items = ACL::getAclByNamespace('default_db/BI_audit_KRS/BI_audit_KRS')->buildQuery(array_merge([
 			'cols' => [ // TODO:? propertyName = []
 				'A_kod',
 				'A_kraj',
@@ -953,17 +976,32 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 				'regon',
 			],
 			// 'f_ID' => "{$id}",
-		])->getItems([
+		], $searchParams))->getItems([
 			//'limit' => 10
 		]);
+		DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
 
 		return [
 			'type' => 'success',
 			'msg' => 'KRS',
-			'__req_args' => $_REQUEST,
 			'__args' => $args,
 			'body' => [
-				'items' => $items,
+				'items' => array_map(function ($item) {
+					// return array_merge($item, [
+					// 	'label' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
+					// 	'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
+					// ]);
+					return [
+						'ID' => $item['ID'],
+						'nazwa' => $item['nazwa'],
+						'nip' => $item['nip'],
+						'krs' => $item['krs'],
+						'regon' => $item['regon'],
+						'S_miejscowosc' => $item['S_miejscowosc'],
+						'label' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
+						'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
+					];
+				}, $items),
 			]
 		];
 	}

+ 60 - 69
tools/Bocian.php.addItemToRaport.js

@@ -33,6 +33,7 @@ var P5UI_AddItemToReport = createReactClass({
     },
     _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, {
@@ -46,6 +47,9 @@ var P5UI_AddItemToReport = createReactClass({
             query: query,
 					})
 				})
+        .then(function(response) {
+          return response.text();
+        })
         .then(function(responseText) {
 					try {
 						return JSON.parse(responseText);
@@ -56,47 +60,28 @@ var P5UI_AddItemToReport = createReactClass({
 				.then(function(result) {
 					if (result.type == 'success') {
 						p5UI__notifyAjaxCallback(result);
-						resolve(result.body);
+            if (result.body && result.body.items && result.body.items.length > 0) {
+              return result.body.items;
+            } else {
+              p5UI__notifyAjaxCallback({ type: 'warning', msg: "Brak danych pasujących do kryteriów wyszukiwania" });
+            }
 					}
 				})
         .then(function(items) {
-          options = items;
-          this.setState({ isSearching: false, options: options });
+          DBG && console.log('items fetched:', items);
+          _setState({ isSearching: false, options: items });
         })
         .catch(function(error) {
-          if(DBG) console.log('request failed', error);
+          DBG && console.log('request failed', error);
         })
-        // setTimeout(function () {
-        //     var options = [];
-        //     options.push({
-        //         ID: 601900,
-        //         nazwa: "ADEGROUP SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ SPÓŁKA KOMANDYTOWA",
-        //         krs: "0000721712", nip: "5862328735", regon: "369609850",
-        //         S_kraj: "POLSKA", S_miejscowosc: "GDYNIA", A_kod: "81-310", A_ulica: "ŚLĄSKA", A_nrDomu: "35/37",
-        //         searchLabel: "ADEGROUP SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ SPÓŁKA KOMANDYTOWA, ŚLĄSKA 35/37, 81-310 GDYNIA, krs: 0000721712, nip: 5862328735, regon: 369609850",
-        //         label: "ADEGROUP SPÓŁKA ..., ŚLĄSKA 35/37, 81-310 GDYNIA"
-        //     })
-        //     options.push({
-        //         ID: 601900,
-        //         nazwa: "BIZNESLIMIT.PL SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ",
-        //         krs: "0000721708", nip: "9452218050", regon: "369608402",
-        //         S_kraj: "POLSKA", S_miejscowosc: "KRAKÓW", A_kod: "31-315", A_ulica: "ELIASZA RADZIKOWSKIEGO", A_nrLokalu: "16", A_nrDomu: "74",
-        //         searchLabel: "BIZNESLIMIT.PL SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ ELIASZA RADZIKOWSKIEGO 74/16, 31-315 KRAKÓW 0000721708 9452218050 369608402",
-        //         label: "BIZNESLIMIT.PL ..., ELIASZA RADZIKOWSKIEGO 74/16, 31-315 KRAKÓW"
-        //     })
-        //     this.setState({ isSearching: false, options: options });
-        // }.bind(this), 1000);
-        // makeAndHandleRequest(query)
-        //   .then(({ options }) => {
-        //     this.setState({
-        //       isLoading: false,
-        //       options,
-        //     });
-        //   });
     },
     componentWillUnmount: function () {
         DBG && console.log("DBG: conponentDidUnmount...");
     },
+    shouldComponentUpdate: function (nextProps, nextState) {
+      DBG && console.log("DBG: shouldComponentUpdate...", { nextProps, nextState });
+      return true;
+    },
     render: function () {
         // '<div>' +
         //   '<p style="text-align:center">' + 'Wybierz bazę' + '</p>' +
@@ -153,7 +138,7 @@ var P5UI_AddItemToReport = createReactClass({
         }
         var handleSearch = this._handleSearch.bind(this);
         var handleSelected = this._handleSelected.bind(this);
-
+        DBG && console.log('DBG: render this.state.options', this.state.options);
         return h('div', {}, [
             h('p', { style: { textAlign: "center" } }, "Wybierz bazę"),
             h('div', { style: { marginBottom: '22px' } },
@@ -176,50 +161,56 @@ var P5UI_AddItemToReport = createReactClass({
                 allowNew: false,
                 multiple: false,
                 options: this.state.options,
-                labelKey: "searchLabel",
-                minLength: 2,
+                // labelKey: "searchLabel",
+                labelKey: function (option) {
+                  return [
+                    option.nazwa.replace('"', ''),
+                    option.nip,
+                    option.krs,
+                    option.regon,
+                    option.S_miejscowosc,
+                  ].join(' ')
+                },
+                minLength: 3,
                 onSearch: handleSearch,
                 placeholder: "Wyszukaj...",
                 onChange: handleSelected,
                 autoFocus: true,
-                // filterBy: function (option, text) {
-                //   console.log('TODO: filterBy...', {option, text});
-                //   return true;
-                // },
+                filterBy: function (option, text) {
+                  console.log('TODO: filterBy...', {option, text});
+                  return true;
+                },
                 renderMenuItemChildren: function (option, props) {
                     return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
                 }
             }),
-            selectedNewItem && h('p', {}, "Dodaj nowy ... " + selectedNewItem),
-            //TODO dlaczego to nie działa
-            // selectedNewItem && h('div', {className='form-group'},[
-              // h('input',{
-              //   className:'form-control required',
-              //   id:'personName',
-              //   placeholder:'Imię'
-              // }),
-              // h('input',{
-              //   className:'form-control required',
-              //   id:'personSurname',
-              //   placeholder:'Nazwisko'
-              // },[]),
-              // h('input',{
-              //   className:'form-control required',
-              //   id:'personNip',
-              //   placeholder:'NIP'
-              // },[]),
-              // h('input',{
-              //   className:'form-control required',
-              //   id:'personPesel',
-              //   placeholder:'personPesel'
-              // },[]),
-              // h('input',{
-              //   className:'form-control required',
-              //   id:'personRegon',
-              //   placeholder:'REGON'
-              // },[])
-            // ]
-            // ),
+            selectedNewItem && h('div', { className: 'form-group' }, [
+              h('input',{
+                className:'form-control required',
+                id:'personName',
+                placeholder:'Imię'
+              }),
+              h('input',{
+                className:'form-control required',
+                id:'personSurname',
+                placeholder:'Nazwisko'
+              }),
+              h('input',{
+                className:'form-control required',
+                id:'personNip',
+                placeholder:'NIP'
+              }),
+              h('input',{
+                className:'form-control required',
+                id:'personPesel',
+                placeholder:'personPesel'
+              }),
+              h('input',{
+                className:'form-control required',
+                id:'personRegon',
+                placeholder:'REGON'
+              })
+            ]),
             // '' === selectedNewItem && h
             (selectedBaza && this.state.selected) && h('div', { style: { marginTop: '22px' } }, [
                 h('button', {
@@ -256,7 +247,7 @@ function createPracownikAjax(event) {
     swal({
         title: "Dodaj osobę lub podmiot",
         width: (getWindowWidth() * 0.8),
-        html: '<div id="createPracownikAjax__searchBaza" style="padding:0 24px 24px 24px"></div>',
+        html: '<div id="createPracownikAjax__searchBaza" style="padding:0 24px 24px 24px; min-height:400px"></div>',
         animation: false,
         showConfirmButton: false,
         showCancelButton: false,