Skip to content

Commit

Permalink
🐛 fixed some weird bugs in Meteor 3.0 which prevented the overview fr…
Browse files Browse the repository at this point in the history
…om displaying projects
  • Loading branch information
faburem committed Jul 25, 2024
1 parent e9c1c62 commit 0cde450
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 57 deletions.
6 changes: 5 additions & 1 deletion imports/api/projects/server/publications.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { checkAuthentication, getGlobalSettingAsync } from '../../../utils/serve
* @returns {Array} - The list of projects for the current user.
*/
Meteor.publish('myprojects', async function myProjects({ projectLimit }) {
await checkAuthentication(this)
if(this.userId) {
await checkAuthentication(this)
} else {
return this.ready()
}
check(projectLimit, Match.Maybe(Number))
return projectLimit ? Projects.find({
$or: [{ userId: this.userId }, { public: true }, { team: this.userId }],
Expand Down
4 changes: 3 additions & 1 deletion imports/startup/client/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ Meteor.startup(() => {
Tracker.autorun(() => {
if (getGlobalSetting('enableOpenIDConnect')) {
import('../../utils/oidc/oidc_client.js').then((Oidc) => {
Oidc.registerOidc()
if(Accounts.oauth.serviceNames().indexOf('oidc') === -1) {
Oidc.registerOidc()
}
})
}
})
Expand Down
4 changes: 2 additions & 2 deletions imports/ui/pages/overview/components/allprojectschart.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ Template.allprojectschart.onRendered(() => {
}
const colors = []
for (const project of templateInstance.projectDistribution.get()) {
colors.push(Projects.findOne({ _id: project._id }).color ? Projects.findOne({ _id: project._id }).color : '#009688')
colors.push(Projects.findOne({ _id: project._id })?.color ? Projects.findOne({ _id: project._id })?.color : '#009688')
}
templateInstance.piechart = new Chart(templateInstance.$('.js-pie-chart-container')[0], {
type: 'pie',
colors,
height: 230,
data: {
labels: templateInstance.projectDistribution.get()
.map((project) => $('<span>').text(Projects.findOne({ _id: project._id }).name).html()),
.map((project) => $('<span>').text(Projects.findOne({ _id: project._id })?.name).html()),
datasets: [{
values: templateInstance.projectDistribution.get().map((project) => project.count),
}],
Expand Down
80 changes: 28 additions & 52 deletions imports/ui/pages/overview/projectlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,33 @@ Template.projectlist.onCreated(function createProjectList() {
this.showArchived = new ReactiveVar(false)
this.projectId = new ReactiveVar(null)
this.period = new ReactiveVar('all')
this.startDate = new ReactiveVar(null)
this.endDate = new ReactiveVar(null)
this.autorun(() => {
this.showArchived.set(FlowRouter.getQueryParam('showArchived') === 'true')
this.period.set(FlowRouter.getQueryParam('period') || 'all')
})
this.autorun(async () => {
if(this.period.get() !== 'all') {
const {startDate, endDate} = await periodToDates(templateInstance.period.get())
this.startDate.set(startDate)
this.endDate.set(endDate)
}
})
})
Template.projectlist.onRendered(() => {
Meteor.setTimeout(() => {
import('sortablejs').then((sortableImport) => {
const Sortable = sortableImport.default
const el = document.querySelector('.js-project-list')
if (el) {
Sortable.create(el, {
handle: '.handle',
onChoose: (evt) => {
document.querySelectorAll('.js-project-list .card-body').forEach((element) => {
element.classList.add('d-none')
})
document.querySelectorAll('.progress-bar').forEach((element) => {
element.classList.add('d-none')
})
},
onEnd: (evt) => {
document.querySelectorAll('.js-project-list .card-body').forEach((element) => {
element.classList.remove('d-none')
})
document.querySelectorAll('.progress-bar').forEach((element) => {
element.classList.remove('d-none')
})
const projectId = $(evt.item).children('.card-body').children('.row.mt-2')[0].id
const priority = evt.newIndex
Meteor.call('updatePriority', { projectId, priority }, (error, result) => {
if (error) {
console.error(error)
}
})
},
})
}
})
}, 1000)
// Template.instance().subscribe('myprojects', {})
})
Template.projectlist.helpers({
async projects() {
projects() {
const templateInstance = Template.instance()
const limit = FlowRouter.getQueryParam('limit') ? Number(FlowRouter.getQueryParam('limit')) : 25
const selector = {}
if(Template.instance().period?.get() && Template.instance().period.get() !== 'all'){
const {startDate, endDate} = await periodToDates(Template.instance().period.get())
selector.$and = [{ $or: [ { startDate: { $exists: false } }, { startDate: { $gte: startDate } }] },
{ $or: [{ endDate: {$exists: false } }, { endDate: { $lte: endDate } }] }]
if(templateInstance.period?.get() && templateInstance.period.get() !== 'all'){
selector.$and = [{ $or: [ { startDate: { $exists: false } }, { startDate: { $gte: templateInstance.startDate.get() } }] },
{ $or: [{ endDate: {$exists: false } }, { endDate: { $lte: templateInstance.endDate.get() } }] }]
}
if(!Template.instance().showArchived?.get()) {
if(!templateInstance.showArchived?.get()) {
if(selector.$and) {
selector.$and.push({ $or: [{ archived: { $exists: false } }, { archived: false }] })
} else {
Expand All @@ -76,14 +52,14 @@ Template.projectlist.helpers({
}
return Projects.find(selector, { sort: { priority: 1, name: 1 }, limit })
},
async moreThanOneProject() {
moreThanOneProject() {
const selector = {}
if(Template.instance().period?.get() && Template.instance().period.get() !== 'all'){
const {startDate, endDate} = await periodToDates(Template.instance().period.get())
selector.$and = [{ $or: [ { startDate: { $exists: false } }, { startDate: { $gte: startDate } }] },
{ $or: [{ endDate: {$exists: false } }, { endDate: { $lte: endDate } }] }]
const templateInstance = Template.instance()
if(templateInstance.period?.get() && templateInstance.period.get() !== 'all'){
selector.$and = [{ $or: [ { startDate: { $exists: false } }, { startDate: { $gte: templateInstance.startDate.get() } }] },
{ $or: [{ endDate: {$exists: false } }, { endDate: { $lte: templateInstance.endDate.get() } }] }]
}
if(!Template.instance().showArchived?.get()) {
if(!templateInstance.showArchived?.get()) {
if(selector.$and) {
selector.$and.push({ $or: [{ archived: { $exists: false } }, { archived: false }] })
} else {
Expand All @@ -105,14 +81,14 @@ Template.projectlist.helpers({
archived(_id) {
return Projects.findOne({ _id }).archived
},
async projectCount() {
projectCount() {
const selector = {}
if(Template.instance().period?.get() && Template.instance().period.get() !== 'all'){
const {startDate, endDate} = await periodToDates(Template.instance().period.get())
selector.$and = [{ $or: [ { startDate: { $exists: false } }, { startDate: { $gte: startDate } }] },
{ $or: [{ endDate: {$exists: false } }, { endDate: { $lte: endDate } }] }]
const templateInstance = Template.instance()
if(templateInstance.period?.get() && templateInstance.period.get() !== 'all'){
selector.$and = [{ $or: [ { startDate: { $exists: false } }, { startDate: { $gte: templateInstance.startDate.get() } }] },
{ $or: [{ endDate: {$exists: false } }, { endDate: { $lte: templateInstance.endDate.get() } }] }]
}
if(!Template.instance().showArchived?.get()) {
if(!templateInstance.showArchived?.get()) {
if(selector.$and) {
selector.$and.push({ $or: [{ archived: { $exists: false } }, { archived: false }] })
} else {
Expand Down
1 change: 1 addition & 0 deletions imports/utils/server_method_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ async function checkAuthentication(context) {
if (!context.userId || meteorUser?.inactive) {
throw new Meteor.Error('notifications.auth_error_method')
}
return true
}
/**
* Checks if the current user is authenticated and an admin.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "titra",
"version": "0.99.1",
"version": "0.99.2",
"private": true,
"scripts": {
"start": "meteor run"
Expand Down

0 comments on commit 0cde450

Please sign in to comment.