From 657b8a03598cf794bf277201d3aaee7dd66b49a0 Mon Sep 17 00:00:00 2001 From: Dauren777 Date: Thu, 11 Jun 2026 04:51:55 +0000 Subject: [PATCH] =?UTF-8?q?sbSync=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C?= =?UTF-8?q?=20=D1=81=D0=B8=D0=BD=D1=85=D1=80=D0=BE=D0=BD=D0=B8=D0=B7=D0=B8?= =?UTF-8?q?=D1=80=D1=83=D0=B5=D1=82=20=D0=B8=20=D0=BF=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D0=B5=D0=B9=20=D0=B8?= =?UTF-8?q?=20=D0=B0=D1=83=D0=B4=D0=B8=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app.html b/app.html index c2a4ea2..c96d395 100644 --- a/app.html +++ b/app.html @@ -103,7 +103,9 @@ function saveA(d){localStorage.setItem("pab_audits",JSON.stringify(d))} function saveU(d){localStorage.setItem("pab_users",JSON.stringify(d))} // Supabase — фоновая синхронизация, не трогает вкладки -function sbSync(){fetch(SBU+"/rest/v1/audits?select=*&order=created_at.desc",{headers:{"apikey":SBK,"Authorization":"Bearer "+SBK}}).then(function(r){return r.json()}).then(function(d){var am=[],ca=getA();d.forEach(function(x){am.push({id:x.id,number:x.number,date:x.date,location:x.location,region:x.region,workType:x.work_type,workerCount:x.worker_count,observer:x.observer,observerRole:x.observer_role,overallSafe:x.overall_safe,categories:x.categories,totalViolations:x.total_violations,dialogue:x.dialogue,photos:x.photos,docs:x.docs,createdBy:x.created_by,createdAt:x.created_at})});ca.forEach(function(a){var found=false;am.forEach(function(b){if(b.id===a.id)found=true});if(!found)am.push(a)});saveA(am)}).catch(function(){})} +function sbSync(){sbPullUsers();sbPullAudits()} +function sbPullUsers(){fetch(SBU+"/rest/v1/users?select=*",{headers:{"apikey":SBK,"Authorization":"Bearer "+SBK}}).then(function(r){return r.json()}).then(function(d){var um=getU();d.forEach(function(x){if(!um[x.login])um[x.login]={pass:x.pass,name:x.name,email:x.email,role:x.role,freq:x.freq,branch:x.branch,dept:x.dept,region:x.region,oblast:x.oblast,city:x.city}});saveU(um)}).catch(function(){})} +function sbPullAudits(){fetch(SBU+"/rest/v1/audits?select=*&order=created_at.desc",{headers:{"apikey":SBK,"Authorization":"Bearer "+SBK}}).then(function(r){return r.json()}).then(function(d){var am=[],ca=getA();d.forEach(function(x){am.push({id:x.id,number:x.number,date:x.date,location:x.location,region:x.region,workType:x.work_type,workerCount:x.worker_count,observer:x.observer,observerRole:x.observer_role,overallSafe:x.overall_safe,categories:x.categories,totalViolations:x.total_violations,dialogue:x.dialogue,photos:x.photos,docs:x.docs,createdBy:x.created_by,createdAt:x.created_at})});ca.forEach(function(a){var found=false;am.forEach(function(b){if(b.id===a.id)found=true});if(!found)am.push(a)});saveA(am)}).catch(function(){})} function sbPushAudit(e){fetch(SBU+"/rest/v1/audits",{method:"POST",headers:{"apikey":SBK,"Authorization":"Bearer "+SBK,"Content-Type":"application/json","Prefer":"resolution=merge-duplicates"},body:JSON.stringify({id:e.id,number:e.number,date:e.date,location:e.location,region:e.region,work_type:e.workType,worker_count:e.workerCount,observer:e.observer,observer_role:e.observerRole,overall_safe:e.overallSafe,categories:e.categories,total_violations:e.totalViolations,dialogue:e.dialogue,photos:e.photos,docs:e.docs,created_by:e.createdBy,created_at:e.createdAt})}).catch(function(){})} // Supabase для фото