Making changes to store more data related to tasks

This commit is contained in:
sairaj mote 2022-11-15 22:25:00 +05:30
parent b26b61e959
commit 46c149ceb7
6 changed files with 69 additions and 62 deletions

View File

@ -1285,6 +1285,15 @@ ul {
#intern_info__name { #intern_info__name {
font-size: 1.5rem; font-size: 1.5rem;
padding: 0.4rem 0.5rem;
border-radius: 0.5rem;
}
#intern_info__name[contenteditable=true] {
background-color: rgba(var(--text-color), 0.1);
}
#edit_intern_name {
min-width: 3.5rem;
} }
.icon--star { .icon--star {

2
css/main.min.css vendored

File diff suppressed because one or more lines are too long

View File

@ -1257,6 +1257,14 @@ ul {
} }
#intern_info__name { #intern_info__name {
font-size: 1.5rem; font-size: 1.5rem;
padding: 0.4rem 0.5rem;
border-radius: 0.5rem;
&[contenteditable="true"] {
background-color: rgba(var(--text-color), 0.1);
}
}
#edit_intern_name {
min-width: 3.5rem;
} }
.icon--star { .icon--star {
fill: var(--orange); fill: var(--orange);

View File

@ -533,7 +533,7 @@
related updates</a> related updates</a>
<div id="explorer_branch_container" class="flex align-center flex-wrap gap-0-3 margin-top-0-5"> <div id="explorer_branch_container" class="flex align-center flex-wrap gap-0-3 margin-top-0-5">
</div> </div>
<div id="explorer_task_list" class="observe-empty-state"></div> <div id="explorer_task_list" class="observe-empty-state margin-top-1"></div>
<h4 class="empty-state">No tasks are added to this projects</h4> <h4 class="empty-state">No tasks are added to this projects</h4>
</section> </section>
</section> </section>
@ -788,7 +788,6 @@
<script id="default_ui_library"> <script id="default_ui_library">
// Global variables // Global variables
const { html, render: renderElem } = uhtml; const { html, render: renderElem } = uhtml;
const domRefs = {}
//Checks for internet connection status //Checks for internet connection status
if (!navigator.onLine) if (!navigator.onLine)
floGlobals.connectionErrorNotification = notify('There seems to be a problem connecting to the internet, Please check you internet connection.', 'error') floGlobals.connectionErrorNotification = notify('There seems to be a problem connecting to the internet, Please check you internet connection.', 'error')
@ -799,22 +798,8 @@
getRef('notification_drawer').remove(floGlobals.connectionErrorNotification) getRef('notification_drawer').remove(floGlobals.connectionErrorNotification)
notify('We are back online.', 'success') notify('We are back online.', 'success')
}) })
// Use instead of document.getElementById
function getRef(elementId) { function getRef(elementId) {
if (!domRefs.hasOwnProperty(elementId)) { return document.getElementById(elementId);
domRefs[elementId] = {
count: 1,
ref: null,
};
}
if (domRefs[elementId].count < 3) {
domRefs[elementId].count += 1;
return document.getElementById(elementId);
} else {
if (!domRefs[elementId].ref?.deref())
domRefs[elementId].ref = new WeakRef(document.getElementById(elementId));
return domRefs[elementId].ref.deref();
}
} }
// returns dom with specified element // returns dom with specified element
@ -1710,7 +1695,7 @@
const render = { const render = {
displayTaskCard(projectCode, branch, task) { displayTaskCard(projectCode, branch, task) {
const { title, category, maxSlots, duration, durationType, reward } = RIBC.getTaskDetails(projectCode, branch, task) const { title, category, maxSlots, duration, durationType, reward } = RIBC.getTaskDetails(projectCode, branch, task)
const assignedInterns = RIBC.getAssignedInterns(projectCode, branch, task) || []; const assignedInterns = RIBC.getAssignedInterns(projectCode, branch, task);
return html` return html`
<li class=${`display-task`}> <li class=${`display-task`}>
<div class="flex align-center space-between"> <div class="flex align-center space-between">
@ -1732,7 +1717,7 @@
${maxSlots ? html` ${maxSlots ? html`
<div class="display-task__detail"> <div class="display-task__detail">
<span class="display-task__detail__title">Slots: </span> <span class="display-task__detail__title">Slots: </span>
<span class="display-task__detail__value">${maxSlots - assignedInterns.length}</span> <span class="display-task__detail__value">${maxSlots - Object.keys(assignedInterns).length}</span>
</div> </div>
`: ''} `: ''}
${reward ? html` ${reward ? html`
@ -1757,11 +1742,11 @@
for (const taskId of displayedTasks) { for (const taskId of displayedTasks) {
availableCategories.add(allTasks[taskId].category) availableCategories.add(allTasks[taskId].category)
const [projectCode, branch, task] = taskId.split('_') const [projectCode, branch, task] = taskId.split('_')
const assignedInterns = RIBC.getAssignedInterns(projectCode, branch, task) || []; const assignedInterns = RIBC.getAssignedInterns(projectCode, branch, task);
if (filterCategory && allTasks[taskId].category !== filterCategory) continue; if (filterCategory && allTasks[taskId].category !== filterCategory) continue;
if (searchQuery && searchQuery !== '' && !allTasks[taskId].title.toLowerCase().includes(searchQuery.toLowerCase())) continue; if (searchQuery && searchQuery !== '' && !allTasks[taskId].title.toLowerCase().includes(searchQuery.toLowerCase())) continue;
if (assignedInterns.length >= allTasks[taskId].maxSlots) continue; if (Object.keys(assignedInterns).length >= allTasks[taskId].maxSlots) continue;
if (userType && userType === 'intern' && floDapps.user.id && assignedInterns.includes(floDapps.user.id)) continue; if (userType && userType === 'intern' && floDapps.user.id && assignedInterns.hasOwnProperty(floDapps.user.id)) continue;
filtered.push(render.displayTaskCard(projectCode, branch, task)) filtered.push(render.displayTaskCard(projectCode, branch, task))
} }
let renderedTasks = filtered let renderedTasks = filtered
@ -1822,10 +1807,10 @@
} }
}) })
const assignedInterns = RIBC.getAssignedInterns(appState.params.id, appState.params.branch, task) || [] const assignedInterns = RIBC.getAssignedInterns(appState.params.id, appState.params.branch, task) || []
const assignedInternsCards = filterMap(assignedInterns, (internFloId) => render.assignedInternCard(internFloId)); const assignedInternsCards = Object.keys(assignedInterns).map(internFloId => render.assignedInternCard(internFloId));
const status = RIBC.getTaskStatus(appState.params.id, appState.params.branch, task) const status = RIBC.getTaskStatus(appState.params.id, appState.params.branch, task)
let applyButton let applyButton
if (!assignedInterns.includes(myFloID) && userType !== 'admin') { if (!assignedInterns.hasOwnProperty(myFloID) && userType !== 'admin') {
const hasApplied = [...RIBC.getTaskRequests(false), ...sessionTaskRequests].find(({ details }) => { const hasApplied = [...RIBC.getTaskRequests(false), ...sessionTaskRequests].find(({ details }) => {
return `${appState.params.id}_${appState.params.branch}_${task}` === details.taskId return `${appState.params.id}_${appState.params.branch}_${task}` === details.taskId
}) })
@ -1865,7 +1850,7 @@
${maxSlots ? html` ${maxSlots ? html`
<div class="display-task__detail"> <div class="display-task__detail">
<span class="display-task__detail__title">Slots: </span> <span class="display-task__detail__title">Slots: </span>
<span class="display-task__detail__value">${maxSlots - assignedInterns.length}</span> <span class="display-task__detail__value">${maxSlots - Object.keys(assignedInterns).length}</span>
</div> </div>
`: ''} `: ''}
${reward ? html` ${reward ? html`
@ -1963,10 +1948,7 @@
const assignedInterns = RIBC.getAssignedInterns(appState.params.id, appState.params.branch, task) const assignedInterns = RIBC.getAssignedInterns(appState.params.id, appState.params.branch, task)
const status = RIBC.getTaskStatus(appState.params.id, appState.params.branch, task) const status = RIBC.getTaskStatus(appState.params.id, appState.params.branch, task)
const taskDetails = { title, description, category, maxSlots, duration, durationType, reward } = RIBC.getTaskDetails(appState.params.id, appState.params.branch, task) const taskDetails = { title, description, category, maxSlots, duration, durationType, reward } = RIBC.getTaskDetails(appState.params.id, appState.params.branch, task)
let assignedInternsCards let assignedInternsCards = Object.keys(assignedInterns).map(internFloId => render.assignedInternCard(internFloId, status === 'incomplete'))
if (assignedInterns) {
assignedInternsCards = filterMap(assignedInterns, (internFloId) => render.assignedInternCard(internFloId, status === 'incomplete'))
}
const branches = getAllBranches(appState.params.id) const branches = getAllBranches(appState.params.id)
const branchesButtons = filterMap(branches, (branch) => { const branchesButtons = filterMap(branches, (branch) => {
const { branchName, parentBranch, startPoint, endPoint } = branch const { branchName, parentBranch, startPoint, endPoint } = branch
@ -2399,7 +2381,7 @@
${maxSlots ? html` ${maxSlots ? html`
<div class="display-task__detail"> <div class="display-task__detail">
<span class="display-task__detail__title">Slots: </span> <span class="display-task__detail__title">Slots: </span>
<span class="display-task__detail__value">${maxSlots - assignedInterns.length}</span> <span class="display-task__detail__value">${maxSlots - Object.keys(assignedInterns).length}</span>
</div> </div>
`: ''} `: ''}
${reward ? html` ${reward ? html`
@ -2547,7 +2529,7 @@
// opens a popup containing various intern information // opens a popup containing various intern information
function showInternInfo(e) { function showInternInfo(e) {
const internFloId = e.target.closest('.intern-card').dataset.internFloId; const internFloId = e.target.closest('.intern-card').dataset.internFloId;
const { completedTasks = {}, active = true } = RIBC.getInternRecord(internFloId) || {} const { joined, completedTasks = {}, active = true } = RIBC.getInternRecord(internFloId) || {}
const internName = RIBC.getInternList()[internFloId] const internName = RIBC.getInternList()[internFloId]
const rating = RIBC.getInternRating(internFloId) const rating = RIBC.getInternRating(internFloId)
let completedTasksCount = 0; let completedTasksCount = 0;
@ -2561,15 +2543,19 @@
if (splitName.length > 1) { if (splitName.length > 1) {
initials += splitName[splitName.length - 1][0] initials += splitName[splitName.length - 1][0]
} }
console.log(joined)
renderElem(getRef('intern_info__wrapper'), html` renderElem(getRef('intern_info__wrapper'), html`
<div class="flex flex-direction-column align-items-center gap-1 text-center"> <div class="flex flex-direction-column align-items-center gap-1-5">
<div id="intern_info__initials" class="intern-card__initials" style=${`--color: var(${getInternColor(internFloId)})`}>${initials}</div> <div id="intern_info__initials" class="intern-card__initials" style=${`--color: var(${getInternColor(internFloId)})`}>${initials}</div>
<div class="flex align-center gap-0-5"> <div class="flex flex-direction-column align-items-center gap-0-5">
<h3 id="intern_info__name">${internName}</h3> <div class="flex align-center gap-0-5">
${userType === 'admin' ? html`<button class="button button--small button--colored" onclick=${toggleInternNameEditing}>Edit</button> ` : ''} <h3 id="intern_info__name" class="text-center">${internName}</h3>
${userType === 'admin' ? html`<button id="edit_intern_name" class="button button--small button--colored" onclick=${toggleInternNameEditing}>Edit</button> ` : ''}
</div>
<sm-copy id="intern_info__flo_id" value=${internFloId}></sm-copy>
</div> </div>
${joined ? html`<p>Joined on ${getFormattedTime(joined, 'date-only')}</p>` : ''}
</div> </div>
<sm-copy id="intern_info__flo_id" value=${internFloId}></sm-copy>
<div id="stats_wrapper"> <div id="stats_wrapper">
<div id="intern_rating" class="stat"> <div id="intern_rating" class="stat">
<div class="stat__display"> <div class="stat__display">
@ -2602,7 +2588,7 @@
color = '--orange' color = '--orange'
} }
setTimeout(() => { setTimeout(() => {
document.getElementById('intern_rating').style = `--progress: ${400 - (rating * 4)}; --rating-color:var(${color})`; getRef('intern_rating').style = `--progress: ${400 - (rating * 4)}; --rating-color:var(${color})`;
}, 100); }, 100);
} }
@ -2700,7 +2686,7 @@
renderElem(getRef('rating_wrapper'), html` renderElem(getRef('rating_wrapper'), html`
<h4>${currentTask.querySelector('.task-title').textContent}</h4> <h4>${currentTask.querySelector('.task-title').textContent}</h4>
<sm-form> <sm-form>
${assignedInterns.map((intern, index) => html` ${Object.keys(assignedInterns).map((intern, index) => html`
<div class="flex flex-direction-column gap-0-5 rating-part" data-intern-id=${intern}> <div class="flex flex-direction-column gap-0-5 rating-part" data-intern-id=${intern}>
<h4>${RIBC.getInternList()[intern]}</h4> <h4>${RIBC.getInternList()[intern]}</h4>
<div class="flex gap-0-5"> <div class="flex gap-0-5">
@ -3244,7 +3230,7 @@
for (const taskKey in allTasks) { for (const taskKey in allTasks) {
const [projectCode, branch, task] = taskKey.split('_') const [projectCode, branch, task] = taskKey.split('_')
const assignedInterns = RIBC.getAssignedInterns(projectCode, branch, task) const assignedInterns = RIBC.getAssignedInterns(projectCode, branch, task)
if (Array.isArray(assignedInterns) && assignedInterns.includes(myFloID)) { if (assignedInterns.hasOwnProperty(myFloID)) {
floGlobals.assignedProjectsList.add(projectCode) floGlobals.assignedProjectsList.add(projectCode)
if (RIBC.getTaskStatus(projectCode, branch, task) === 'incomplete') { if (RIBC.getTaskStatus(projectCode, branch, task) === 'incomplete') {
floGlobals.assignedTasks.add(taskKey); floGlobals.assignedTasks.add(taskKey);
@ -3339,7 +3325,7 @@
return allInterns[a].toLowerCase().localeCompare(allInterns[b].toLowerCase()) return allInterns[a].toLowerCase().localeCompare(allInterns[b].toLowerCase())
}) })
if (availableInternsOnly) { if (availableInternsOnly) {
arrayOfInterns = arrayOfInterns.filter(intern => !RIBC.getAssignedInterns(appState.params.id, appState.params.branch, currentTask.dataset.taskId)?.includes(intern)) arrayOfInterns = arrayOfInterns.filter(intern => !RIBC.getAssignedInterns(appState.params.id, appState.params.branch, currentTask.dataset.taskId)?.hasOwnProperty(intern))
} }
if (searchKey === '') { if (searchKey === '') {
filtered = (sortByRating ? highPerformingInterns : arrayOfInterns).map(floId => { filtered = (sortByRating ? highPerformingInterns : arrayOfInterns).map(floId => {

View File

@ -104,7 +104,7 @@
Ribc.getInternList = () => _.internList; Ribc.getInternList = () => _.internList;
Ribc.getInternRating = (floID) => _.internRating[floID]; Ribc.getInternRating = (floID) => _.internRating[floID];
Ribc.getInternRecord = (floID) => _.internRecord[floID]; Ribc.getInternRecord = (floID) => _.internRecord[floID];
Ribc.getAssignedInterns = (projectCode, branch, taskNumber) => _.internsAssigned[projectCode + "_" + branch + "_" + taskNumber] Ribc.getAssignedInterns = (projectCode, branch, taskNumber) => _.internsAssigned[projectCode + "_" + branch + "_" + taskNumber] || {};
Ribc.getAllTasks = () => _.projectTaskDetails Ribc.getAllTasks = () => _.projectTaskDetails
Ribc.getDisplayedTasks = () => floGlobals.appObjects.RIBC.displayedTasks || []; Ribc.getDisplayedTasks = () => floGlobals.appObjects.RIBC.displayedTasks || [];
@ -160,16 +160,20 @@
floCloudAPI.noteApplicationData(vectorClock, status).then(_ => null).catch(e => console.error(e)) floCloudAPI.noteApplicationData(vectorClock, status).then(_ => null).catch(e => console.error(e))
return status; return status;
} }
Admin.initInternRecord = function (floID) {
if (!_.internRecord[floID])
_.internRecord[floID] = {
active: true,
joined: Date.now(),
completedTasks: {},
}
}
const addIntern = Admin.addIntern = function (floID, internName) { const addIntern = Admin.addIntern = function (floID, internName) {
if (floID in _.internList) if (floID in _.internList)
return false return false
_.internList[floID] = internName _.internList[floID] = internName
_.internRating[floID] = 0 _.internRating[floID] = 0
_.internRecord[floID] = { Admin.initInternRecord(floID)
active: true,
completedTasks: {},
}
return true; return true;
} }
Admin.renameIntern = function (floID, newName) { Admin.renameIntern = function (floID, newName) {
@ -186,19 +190,15 @@
delete _.internRating[floID] delete _.internRating[floID]
delete _.internRecord[floID] delete _.internRecord[floID]
for (const taskId in _.projectTaskDetails) { for (const taskId in _.projectTaskDetails) {
if (_.internsAssigned[taskId].includes(floID)) if (_.internsAssigned[taskId].hasOwnProperty(floID))
_.internsAssigned[taskId] = _.internsAssigned[taskId].filter(id => id != floID) delete _.internsAssigned[taskId][floID]
} }
return true; return true;
} }
Admin.addTaskScore = function (floID, taskId, points, details = {}) { Admin.addTaskScore = function (floID, taskId, points, details = {}) {
if (!(floID in _.internList)) if (!(floID in _.internList))
return false; return false;
if (!_.internRecord[floID]) Admin.initInternRecord(floID)
_.internRecord[floID] = {
active: true,
completedTasks: {},
}
_.internRecord[floID].completedTasks[taskId] = { _.internRecord[floID].completedTasks[taskId] = {
points, points,
...details ...details
@ -255,19 +255,23 @@
} }
const assignInternToTask = Admin.assignInternToTask = function (floID, projectCode, branch, taskNumber) { const assignInternToTask = Admin.assignInternToTask = function (floID, projectCode, branch, taskNumber) {
var index = projectCode + "_" + branch + "_" + taskNumber const key = projectCode + "_" + branch + "_" + taskNumber
if (!Array.isArray(_.internsAssigned[index])) if (!_.internsAssigned[key])
_.internsAssigned[index] = [] _.internsAssigned[key] = {}
if (!_.internsAssigned[index].includes(floID)) { if (!_.internsAssigned[key].hasOwnProperty(floID)) {
_.internsAssigned[index].push(floID) _.internsAssigned[key][floID] = { assignedOn: Date.now() }
return true return true
} else } else
return false return false
} }
Admin.unassignInternFromTask = function (floID, projectCode, branch, taskNumber) { Admin.unassignInternFromTask = function (floID, projectCode, branch, taskNumber) {
const index = projectCode + "_" + branch + "_" + taskNumber const key = projectCode + "_" + branch + "_" + taskNumber
_.internsAssigned[index] = _.internsAssigned[index].filter(id => id != floID) if (_.internsAssigned[key] && _.internsAssigned[key].hasOwnProperty(floID)) {
delete _.internsAssigned[key][floID]
return true
} else
return false
} }
Admin.putTaskStatus = function (taskStatus, projectCode, branch, taskNumber) { Admin.putTaskStatus = function (taskStatus, projectCode, branch, taskNumber) {

2
scripts/ribc.min.js vendored

File diff suppressed because one or more lines are too long