I have set up a system to track tasks given to my employees. I have given each employee a dymanic profile page, and within that page I have a repeater connected to a jobs dataset. I have filtered the repeater by staff member and whether or not the “COMPLETED” boolean field is checked.
I hit a problem yesterday where the repeater for “incomplete” jobs was still showing a couple of “completed” jobs. It seemed as though deleting the records in the dataset and adding everything again solved the issue. Which obviously will not be ideal if this happens once live and in use.
The main problem I have now is the repeater not showing all the results.
I have a “send job” page where Managers etc can add the details of a job and who it is for, and send it to the jobs dataset. This seems to work fine. But the repeater on the profile page will not return any of the entries I’ve added through this input. It is only displaying the jobs I’ve added through the content manager window. In the split second before my filters kick in on my repeater I can see the missing jobs, then they vanish.
I only started to learn Javascript in December, so I imagine there are a lot of issues in my code for this page, I’ll include it all below. I’m very thankful for any advice anyone may have, even if not directly to do with this issue, but my code in general!
I also wondered if I could be creating issues by connecting or filtering some parts of a dataset etc through the wix editor, and other parts through script in Velo. Should I be doing this all through script?
Thanks again
import wixData from 'wix-data';
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
//------------------------------------------------------------FILTER PENDING BY MECHANIC--------------------------------------------
export function jobsPending_ready() {
//filter jobs pending by not completed, mechanic, and current user.
$w("#dynamicDataset").onReady( () => {
let currentStaff = $w("#dynamicDataset").getCurrentItem();
let staffId = currentStaff._id;
$w("#jobsPending").setFilter( wixData.filter()
.eq("completed", false)
.and(
wixData.filter()
.eq("newField", staffId)
.or(
wixData.filter()
.eq("newField", "60eb6b79-e5b1-4cc4-b376-a6fdce88d17e")
)))
//set sort to grade and created date
$w("#jobsPending").setSort(wixData.sort()
.descending("grade")
.ascending("_createdDate")
//grade high to low
//created date old to new
);
wixData.query("JOBSPAGE")
.eq("completed", false)
.and(wixData.query()
.eq("newField", staffId)
.or(wixData.query()
.eq("newField", "60eb6b79-e5b1-4cc4-b376-a6fdce88d17e")
))
.find()
.then( (results) => {
let pendingTotal = results.length;
let pendingTotalString = pendingTotal.toString();
console. log(pendingTotal)
console. log(pendingTotalString)
$w('#pendingTotal').text = pendingTotalString;
})
})}
//--------------------------------------------------------------OPEN PENDING JOB-----------------------------------
export function openJobPending_click(event) {
$w("#repeater1").onItemReady( ($item, itemData, index) => {
let jobId = itemData._id;
return wixLocation.to("/jobs-1/" + jobId)
})}
//----------------------------------------------------------------COMPLETED-----------------------------------------
export function jobsCompleted_ready() {
//filter jobs completed by completed, mechanic and current user.
$w("#dynamicDataset").onReady( () => {
let currentStaff = $w("#dynamicDataset").getCurrentItem();
let staffId = currentStaff._id;
$w("#jobsCompleted").setFilter( wixData.filter()
.eq("completed", true)
.and(
wixData.filter()
.eq("newField", staffId)
.or(
wixData.filter()
.eq("newField", "60eb6b79-e5b1-4cc4-b376-a6fdce88d17e")
))
)
$w("#jobsCompleted").setSort(wixData.sort()
.descending("grade")
.descending("_updatedDate")
//grade high to low
//created date old to new
)
wixData.query("JOBSPAGE")
.eq("completed", true)
.and(wixData.query()
.eq("newField", staffId)
.or(wixData.query()
.eq("newField", "60eb6b79-e5b1-4cc4-b376-a6fdce88d17e")
))
.find()
.then( (results) => {
let completeTotal = results.length;
let completeTotalString = completeTotal.toString();
console. log(completeTotal)
console. log(completeTotalString)
$w('#completedTotal').text = completeTotalString;
})
})}
// ------------------------------------CLOCK IN--------------------------------
export function clockIn_click(event) {
let currentStaff = $w("#dynamicDataset").getCurrentItem();
let staffId = currentStaff._id;
let toInsert = {
"staffMemeber": staffId,
"inout": "IN",
};
wixData.insert("CHECKIN", toInsert)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
}
//----------------------------------------------------------CLOCK OUT----------------------------------------
export function clockOut_click(event) {
let currentStaff = $w("#dynamicDataset").getCurrentItem();
let staffId = currentStaff._id;
let today = new Date();
console.log(today);
today.setHours(0);
today.setMinutes(0);
today.setSeconds(0);
console.log(today);
let todayTime = today.getTime()
let yesterdayTime = todayTime - 86400000;
let yesterday = new Date(yesterdayTime);
console.log(yesterday)
let currentTimeDate = new Date();
wixData.query("CHECKIN")
.eq("staffMemeber", staffId)
.ge("_createdDate", yesterday)
.find()
.then( (results) => {
if(results.items.length > 0) {
let item = results.items[0];
console.log(item)
item.checkOut = currentTimeDate; // updated check out time
console.log(item)
wixData.update("CHECKIN", item);
} else {
// handle case where no matching items found
}
} )
.catch( (err) => {
let errorMsg = err;
} );
}