phan trang dong bo du lieu

This commit is contained in:
dongpd 2020-12-24 15:43:24 +07:00
parent b26814bb97
commit 22f3a3f650
3 changed files with 12 additions and 11 deletions

View File

@ -115,8 +115,8 @@ class ApiController extends Controller {
} }
} }
public function actionGetAllFeatures() { public function actionGetAllFeatures($offset = 0, $limit = 10) {
$listManagement = ListManagement::find()->all(); $listManagement = ListManagement::find()->limit($limit)->offset($offset)->all();
$allFeatures = []; $allFeatures = [];
foreach ($listManagement as $key => $value) { foreach ($listManagement as $key => $value) {
$features = json_decode($value->image, true); $features = json_decode($value->image, true);

View File

@ -516,7 +516,7 @@ class ListManagementController extends Controller {
public function actionUpdateFeature() { public function actionUpdateFeature() {
if (Yii::$app->request->isAjax) { if (Yii::$app->request->isAjax) {
Yii::$app->response->format = "json"; Yii::$app->response->format = "json";
file_get_contents("http://localhost:2305/update-feature"); file_get_contents("http://localhost:2305/update-feature?total=" . ListManagement::find()->count());
return ["status" => true]; return ["status" => true];
} }
} }

View File

@ -425,12 +425,10 @@ function _syncFromServer() {
$("#progress-totals").html(lists.length); $("#progress-totals").html(lists.length);
$("#progress-form").removeClass("hidden"); $("#progress-form").removeClass("hidden");
totals = lists.length; totals = lists.length;
for (var i = 0; i < lists.length; i++) { syncFeature(lists[0], lists);
syncFeature(lists[i]);
}
} }
function syncFeature(id) { function syncFeature(id, fullData) {
$.ajax({ $.ajax({
url: $("input[name='sync_feature_url']").val(), url: $("input[name='sync_feature_url']").val(),
type: 'POST', type: 'POST',
@ -438,6 +436,7 @@ function syncFeature(id) {
id: id id: id
}, },
success: function (data) { success: function (data) {
console.log(data, progress);
progress++; progress++;
$("#progress-current").html(parseInt($("#progress-current").html()) + 1); $("#progress-current").html(parseInt($("#progress-current").html()) + 1);
var percent = parseInt(progress / totals * 100); var percent = parseInt(progress / totals * 100);
@ -448,6 +447,8 @@ function syncFeature(id) {
common.modalBlock(false); common.modalBlock(false);
updateFeature(); updateFeature();
progress = 0; progress = 0;
} else {
syncFeature(fullData[progress], fullData);
} }
}, },
error: function (jqXHR, textStatus, errorThrown) { error: function (jqXHR, textStatus, errorThrown) {
@ -521,12 +522,10 @@ function _syncToServer() {
$("#progress-totals").html(lists.length); $("#progress-totals").html(lists.length);
$("#progress-form").removeClass("hidden"); $("#progress-form").removeClass("hidden");
totalsToServer = lists.length; totalsToServer = lists.length;
for (var i = 0; i < lists.length; i++) { syncFeatureToServer(lists[0], lists);
syncFeatureToServer(lists[i]);
}
} }
var error = 0; var error = 0;
function syncFeatureToServer(id) { function syncFeatureToServer(id, fullData) {
$.ajax({ $.ajax({
url: $("input[name='sync_feature_to_server_url']").val(), url: $("input[name='sync_feature_to_server_url']").val(),
type: 'POST', type: 'POST',
@ -550,6 +549,8 @@ function syncFeatureToServer(id) {
alert("Đồng bộ dữ liệu hoàn thành"); alert("Đồng bộ dữ liệu hoàn thành");
window.location.reload(true); window.location.reload(true);
}, 2000) }, 2000)
} else {
syncFeature(fullData[progressToServer], fullData);
} }
}, },
error: function (jqXHR, textStatus, errorThrown) { error: function (jqXHR, textStatus, errorThrown) {