Ver código fonte

+ Windyk force update selected for Admin

Piotr Labudda 6 anos atrás
pai
commit
4482ccef74

+ 15 - 0
SE/se-lib/Route/UrlAction/WindykacjaUpdateStatus.php

@@ -13,6 +13,7 @@ class Route_UrlAction_WindykacjaUpdateStatus extends RouteBase {
 		$postTask = V::get('_postTask', '', $_POST);
 		switch ($postTask) { // PostTask outputs html; TODO: move to WPS functions
 			case 'updateSelected': return $this->updateSelectedPostTask();
+			case 'forceUpdateSelected': return $this->forceUpdateSelectedPostTask();
 			case 'updateAll': return $this->updateAllPostTask();
 		}
 
@@ -103,6 +104,18 @@ class Route_UrlAction_WindykacjaUpdateStatus extends RouteBase {
 		DBG::log("DBG:testSleep::END");
 	}
 
+	function forceUpdateSelectedPostTask() {
+		$sqlSelected = FeatureAttrSelected::getAllSelectedAsSqlSubQuery($typeName = "default_db/USERS2_WINDYKACJA_STATUS");
+		DB::getPDO()->execSql("
+			update USERS2_WINDYKACJA_STATUS t
+			set t.A_STATUS_UPDATE_DATE = :yesterday
+			where t.ID in ( {$sqlSelected} )
+		", [
+			':yesterday' => date("Y-m-d", mktime(0,0,0, date("m"), date("d") - 1, date("Y")))
+		]);
+
+		UI::layout([ $this, 'updateSelectedPostTaskView' ]);
+	}
 	function updateSelectedPostTask() { UI::layout([ $this, 'updateSelectedPostTaskView' ]); }
 	function updateSelectedPostTaskView() {
 		$totalSelected = FeatureAttrSelected::getTotalSelected($typeName = "default_db/USERS2_WINDYKACJA_STATUS");
@@ -158,6 +171,8 @@ class Route_UrlAction_WindykacjaUpdateStatus extends RouteBase {
 			'HTML_ID' => "p5-widget-windykacja-status-update",
 			'TOTAL' => $totalSelected,
 			'EXECUTE_SINGLE_TASK_URL' => $this->getLink("updateOneFromSelectedAjaxTask"),
+			'ALLOW_FORCE_UPDATE' => User::isAdmin(),
+			'FORCE_UPDATE_POST_DATA' => User::isAdmin() ? [ '_postTask' => 'forceUpdateSelected' ] : null,
 		]);
 
 		echo UI::h('div', [ 'style' => "font-size:14px" ], [

+ 25 - 2
SE/se-lib/Route/UrlAction/WindykacjaUpdateStatus.php.view.js

@@ -7,6 +7,8 @@ if (!HTML_ID) throw "Missing HTML_ID";
 if (!TOTAL) throw "Missing TOTAL";
 if (!EXECUTE_SINGLE_TASK_URL) throw "Missing EXECUTE_SINGLE_TASK_URL";
 if (!global.p5VendorJs) throw "Missing vendor.js";
+var ALLOW_FORCE_UPDATE = ALLOW_FORCE_UPDATE || false;
+var FORCE_UPDATE_POST_DATA = FORCE_UPDATE_POST_DATA || [];
 
 var createReactClass = global.p5VendorJs.createReactClass;
 var h = global.p5VendorJs.React.createElement;
@@ -115,6 +117,10 @@ var P5UI__WindykacjaStatusUpdate = createReactClass({
 		event.preventDefault()
 		location.reload()
 	},
+	handleClickForceRestart: function (event) {
+		event.preventDefault()
+		
+	},
 	handleClickPause: function (event) {
 		event.preventDefault()
 		this.setState({ execAgain: false })
@@ -162,8 +168,8 @@ var P5UI__WindykacjaStatusUpdate = createReactClass({
 					]),
 
 					(this.state.responseBody)
-					? h('p', {}, "Wykonano " + this.state.responseBody.totalDone + " z " + this.state.responseBody.total)
-					: '',
+					?	h('p', {}, "Wykonano " + this.state.responseBody.totalDone + " z " + this.state.responseBody.total)
+					:	'',
 
 					(this.state.errorMsg) ? h('div', { className: "alert alert-danger" }, [
 						this.state.errorMsg,
@@ -171,15 +177,32 @@ var P5UI__WindykacjaStatusUpdate = createReactClass({
 						h('button', { className: "btn btn-primary", onClick: this.handleClickRestart }, "Uruchom ponownie")
 					]) : "",
 
+					(isDone && !this.state.errorMsg && this.props.allowForceUpdate)
+					?	h('div', { style: { float: "right" } }, [
+							h(P5UI__PostButton, { data: this.props.forceUpdatePostData, className: "btn btn-xs btn-warning", label: "Wymuś ponowne uruchomienie" })
+						])
+					:	'',
 				]),
 			]),
 		]);
 	}
 });
 
+var P5UI__PostButton = function (props) { // @props: { label: string, data: { key: value, ... } }
+	return h('form', { 'style' : { display : "inline" }, method: "POST" }, [
+		h('div', {}, Object.keys(props.data).map(function (key) {
+			return h('input', { type: "hidden", name: key, value: props.data[key] });
+		})),
+		h('button', { className: props.className || "btn btn-primary", type: "submit" }, props.label)
+	]);
+}
+
+
 ReactDOM.render(
 	h(P5UI__WindykacjaStatusUpdate, {
 		total: TOTAL,
+		allowForceUpdate: ALLOW_FORCE_UPDATE,
+		forceUpdatePostData: FORCE_UPDATE_POST_DATA,
 	}),
 	document.getElementById(HTML_ID)
 )