Compare commits
No commits in common. "ai-dev" and "master" have entirely different histories.
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,8 +1,3 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
*/node_modules/
|
*/node_modules/
|
||||||
*/build/
|
*/build/
|
||||||
|
|
||||||
**/node_modules/
|
|
||||||
**/build/
|
|
||||||
.DS_Store
|
|
||||||
.env
|
|
||||||
File diff suppressed because one or more lines are too long
@ -1,435 +0,0 @@
|
|||||||
const db = require('../models');
|
|
||||||
const FileDBApi = require('./file');
|
|
||||||
const crypto = require('crypto');
|
|
||||||
const Utils = require('../utils');
|
|
||||||
|
|
||||||
const Sequelize = db.Sequelize;
|
|
||||||
const Op = Sequelize.Op;
|
|
||||||
|
|
||||||
module.exports = class ScoutingDBApi {
|
|
||||||
static async create(data, options) {
|
|
||||||
const currentUser = (options && options.currentUser) || { id: null };
|
|
||||||
const transaction = (options && options.transaction) || undefined;
|
|
||||||
|
|
||||||
const scouting = await db.scouting.create(
|
|
||||||
{
|
|
||||||
id: data.id || undefined,
|
|
||||||
|
|
||||||
team_number: data.team_number || null,
|
|
||||||
coral_l1: data.coral_l1 || null,
|
|
||||||
coral_l2: data.coral_l2 || null,
|
|
||||||
coral_l3: data.coral_l3 || null,
|
|
||||||
coral_l4: data.coral_l4 || null,
|
|
||||||
algae_processor: data.algae_processor || null,
|
|
||||||
algae_net: data.algae_net || null,
|
|
||||||
importHash: data.importHash || null,
|
|
||||||
createdById: currentUser.id,
|
|
||||||
updatedById: currentUser.id,
|
|
||||||
},
|
|
||||||
{ transaction },
|
|
||||||
);
|
|
||||||
|
|
||||||
return scouting;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async bulkImport(data, options) {
|
|
||||||
const currentUser = (options && options.currentUser) || { id: null };
|
|
||||||
const transaction = (options && options.transaction) || undefined;
|
|
||||||
|
|
||||||
// Prepare data - wrapping individual data transformations in a map() method
|
|
||||||
const scoutingData = data.map((item, index) => ({
|
|
||||||
id: item.id || undefined,
|
|
||||||
|
|
||||||
team_number: item.team_number || null,
|
|
||||||
coral_l1: item.coral_l1 || null,
|
|
||||||
coral_l2: item.coral_l2 || null,
|
|
||||||
coral_l3: item.coral_l3 || null,
|
|
||||||
coral_l4: item.coral_l4 || null,
|
|
||||||
algae_processor: item.algae_processor || null,
|
|
||||||
algae_net: item.algae_net || null,
|
|
||||||
importHash: item.importHash || null,
|
|
||||||
createdById: currentUser.id,
|
|
||||||
updatedById: currentUser.id,
|
|
||||||
createdAt: new Date(Date.now() + index * 1000),
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Bulk create items
|
|
||||||
const scouting = await db.scouting.bulkCreate(scoutingData, {
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
// For each item created, replace relation files
|
|
||||||
|
|
||||||
return scouting;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async update(id, data, options) {
|
|
||||||
const currentUser = (options && options.currentUser) || { id: null };
|
|
||||||
const transaction = (options && options.transaction) || undefined;
|
|
||||||
|
|
||||||
const scouting = await db.scouting.findByPk(id, {}, { transaction });
|
|
||||||
|
|
||||||
const updatePayload = {};
|
|
||||||
|
|
||||||
if (data.team_number !== undefined)
|
|
||||||
updatePayload.team_number = data.team_number;
|
|
||||||
|
|
||||||
if (data.coral_l1 !== undefined) updatePayload.coral_l1 = data.coral_l1;
|
|
||||||
|
|
||||||
if (data.coral_l2 !== undefined) updatePayload.coral_l2 = data.coral_l2;
|
|
||||||
|
|
||||||
if (data.coral_l3 !== undefined) updatePayload.coral_l3 = data.coral_l3;
|
|
||||||
|
|
||||||
if (data.coral_l4 !== undefined) updatePayload.coral_l4 = data.coral_l4;
|
|
||||||
|
|
||||||
if (data.algae_processor !== undefined)
|
|
||||||
updatePayload.algae_processor = data.algae_processor;
|
|
||||||
|
|
||||||
if (data.algae_net !== undefined) updatePayload.algae_net = data.algae_net;
|
|
||||||
|
|
||||||
updatePayload.updatedById = currentUser.id;
|
|
||||||
|
|
||||||
await scouting.update(updatePayload, { transaction });
|
|
||||||
|
|
||||||
return scouting;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async deleteByIds(ids, options) {
|
|
||||||
const currentUser = (options && options.currentUser) || { id: null };
|
|
||||||
const transaction = (options && options.transaction) || undefined;
|
|
||||||
|
|
||||||
const scouting = await db.scouting.findAll({
|
|
||||||
where: {
|
|
||||||
id: {
|
|
||||||
[Op.in]: ids,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await db.sequelize.transaction(async (transaction) => {
|
|
||||||
for (const record of scouting) {
|
|
||||||
await record.update({ deletedBy: currentUser.id }, { transaction });
|
|
||||||
}
|
|
||||||
for (const record of scouting) {
|
|
||||||
await record.destroy({ transaction });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return scouting;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async remove(id, options) {
|
|
||||||
const currentUser = (options && options.currentUser) || { id: null };
|
|
||||||
const transaction = (options && options.transaction) || undefined;
|
|
||||||
|
|
||||||
const scouting = await db.scouting.findByPk(id, options);
|
|
||||||
|
|
||||||
await scouting.update(
|
|
||||||
{
|
|
||||||
deletedBy: currentUser.id,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
transaction,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
await scouting.destroy({
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
return scouting;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async findBy(where, options) {
|
|
||||||
const transaction = (options && options.transaction) || undefined;
|
|
||||||
|
|
||||||
const scouting = await db.scouting.findOne({ where }, { transaction });
|
|
||||||
|
|
||||||
if (!scouting) {
|
|
||||||
return scouting;
|
|
||||||
}
|
|
||||||
|
|
||||||
const output = scouting.get({ plain: true });
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async findAll(filter, options) {
|
|
||||||
const limit = filter.limit || 0;
|
|
||||||
let offset = 0;
|
|
||||||
let where = {};
|
|
||||||
const currentPage = +filter.page;
|
|
||||||
|
|
||||||
offset = currentPage * limit;
|
|
||||||
|
|
||||||
const orderBy = null;
|
|
||||||
|
|
||||||
const transaction = (options && options.transaction) || undefined;
|
|
||||||
|
|
||||||
let include = [];
|
|
||||||
|
|
||||||
if (filter) {
|
|
||||||
if (filter.id) {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
['id']: Utils.uuid(filter.id),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.team_numberRange) {
|
|
||||||
const [start, end] = filter.team_numberRange;
|
|
||||||
|
|
||||||
if (start !== undefined && start !== null && start !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
team_number: {
|
|
||||||
...where.team_number,
|
|
||||||
[Op.gte]: start,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (end !== undefined && end !== null && end !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
team_number: {
|
|
||||||
...where.team_number,
|
|
||||||
[Op.lte]: end,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.coral_l1Range) {
|
|
||||||
const [start, end] = filter.coral_l1Range;
|
|
||||||
|
|
||||||
if (start !== undefined && start !== null && start !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
coral_l1: {
|
|
||||||
...where.coral_l1,
|
|
||||||
[Op.gte]: start,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (end !== undefined && end !== null && end !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
coral_l1: {
|
|
||||||
...where.coral_l1,
|
|
||||||
[Op.lte]: end,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.coral_l2Range) {
|
|
||||||
const [start, end] = filter.coral_l2Range;
|
|
||||||
|
|
||||||
if (start !== undefined && start !== null && start !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
coral_l2: {
|
|
||||||
...where.coral_l2,
|
|
||||||
[Op.gte]: start,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (end !== undefined && end !== null && end !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
coral_l2: {
|
|
||||||
...where.coral_l2,
|
|
||||||
[Op.lte]: end,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.coral_l3Range) {
|
|
||||||
const [start, end] = filter.coral_l3Range;
|
|
||||||
|
|
||||||
if (start !== undefined && start !== null && start !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
coral_l3: {
|
|
||||||
...where.coral_l3,
|
|
||||||
[Op.gte]: start,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (end !== undefined && end !== null && end !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
coral_l3: {
|
|
||||||
...where.coral_l3,
|
|
||||||
[Op.lte]: end,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.coral_l4Range) {
|
|
||||||
const [start, end] = filter.coral_l4Range;
|
|
||||||
|
|
||||||
if (start !== undefined && start !== null && start !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
coral_l4: {
|
|
||||||
...where.coral_l4,
|
|
||||||
[Op.gte]: start,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (end !== undefined && end !== null && end !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
coral_l4: {
|
|
||||||
...where.coral_l4,
|
|
||||||
[Op.lte]: end,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.algae_processorRange) {
|
|
||||||
const [start, end] = filter.algae_processorRange;
|
|
||||||
|
|
||||||
if (start !== undefined && start !== null && start !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
algae_processor: {
|
|
||||||
...where.algae_processor,
|
|
||||||
[Op.gte]: start,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (end !== undefined && end !== null && end !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
algae_processor: {
|
|
||||||
...where.algae_processor,
|
|
||||||
[Op.lte]: end,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.algae_netRange) {
|
|
||||||
const [start, end] = filter.algae_netRange;
|
|
||||||
|
|
||||||
if (start !== undefined && start !== null && start !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
algae_net: {
|
|
||||||
...where.algae_net,
|
|
||||||
[Op.gte]: start,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (end !== undefined && end !== null && end !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
algae_net: {
|
|
||||||
...where.algae_net,
|
|
||||||
[Op.lte]: end,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.active !== undefined) {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
active: filter.active === true || filter.active === 'true',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.createdAtRange) {
|
|
||||||
const [start, end] = filter.createdAtRange;
|
|
||||||
|
|
||||||
if (start !== undefined && start !== null && start !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
['createdAt']: {
|
|
||||||
...where.createdAt,
|
|
||||||
[Op.gte]: start,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (end !== undefined && end !== null && end !== '') {
|
|
||||||
where = {
|
|
||||||
...where,
|
|
||||||
['createdAt']: {
|
|
||||||
...where.createdAt,
|
|
||||||
[Op.lte]: end,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const queryOptions = {
|
|
||||||
where,
|
|
||||||
include,
|
|
||||||
distinct: true,
|
|
||||||
order:
|
|
||||||
filter.field && filter.sort
|
|
||||||
? [[filter.field, filter.sort]]
|
|
||||||
: [['createdAt', 'desc']],
|
|
||||||
transaction: options?.transaction,
|
|
||||||
logging: console.log,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!options?.countOnly) {
|
|
||||||
queryOptions.limit = limit ? Number(limit) : undefined;
|
|
||||||
queryOptions.offset = offset ? Number(offset) : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const { rows, count } = await db.scouting.findAndCountAll(queryOptions);
|
|
||||||
|
|
||||||
return {
|
|
||||||
rows: options?.countOnly ? [] : rows,
|
|
||||||
count: count,
|
|
||||||
};
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error executing query:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async findAllAutocomplete(query, limit, offset) {
|
|
||||||
let where = {};
|
|
||||||
|
|
||||||
if (query) {
|
|
||||||
where = {
|
|
||||||
[Op.or]: [
|
|
||||||
{ ['id']: Utils.uuid(query) },
|
|
||||||
Utils.ilike('scouting', 'team_number', query),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const records = await db.scouting.findAll({
|
|
||||||
attributes: ['id', 'team_number'],
|
|
||||||
where,
|
|
||||||
limit: limit ? Number(limit) : undefined,
|
|
||||||
offset: offset ? Number(offset) : undefined,
|
|
||||||
orderBy: [['team_number', 'ASC']],
|
|
||||||
});
|
|
||||||
|
|
||||||
return records.map((record) => ({
|
|
||||||
id: record.id,
|
|
||||||
label: record.team_number,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -1,72 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async up(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.createTable(
|
|
||||||
'scouting',
|
|
||||||
{
|
|
||||||
id: {
|
|
||||||
type: Sequelize.DataTypes.UUID,
|
|
||||||
defaultValue: Sequelize.DataTypes.UUIDV4,
|
|
||||||
primaryKey: true,
|
|
||||||
},
|
|
||||||
createdById: {
|
|
||||||
type: Sequelize.DataTypes.UUID,
|
|
||||||
references: {
|
|
||||||
key: 'id',
|
|
||||||
model: 'users',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
updatedById: {
|
|
||||||
type: Sequelize.DataTypes.UUID,
|
|
||||||
references: {
|
|
||||||
key: 'id',
|
|
||||||
model: 'users',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
createdAt: { type: Sequelize.DataTypes.DATE },
|
|
||||||
updatedAt: { type: Sequelize.DataTypes.DATE },
|
|
||||||
deletedAt: { type: Sequelize.DataTypes.DATE },
|
|
||||||
importHash: {
|
|
||||||
type: Sequelize.DataTypes.STRING(255),
|
|
||||||
allowNull: true,
|
|
||||||
unique: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ transaction },
|
|
||||||
);
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async down(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.dropTable('scouting', { transaction });
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async up(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.addColumn(
|
|
||||||
'scouting',
|
|
||||||
'coral_l1',
|
|
||||||
{
|
|
||||||
type: Sequelize.DataTypes.INTEGER,
|
|
||||||
},
|
|
||||||
{ transaction },
|
|
||||||
);
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async down(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.removeColumn('scouting', 'coral_l1', {
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async up(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.addColumn(
|
|
||||||
'scouting',
|
|
||||||
'coral_l2',
|
|
||||||
{
|
|
||||||
type: Sequelize.DataTypes.INTEGER,
|
|
||||||
},
|
|
||||||
{ transaction },
|
|
||||||
);
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async down(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.removeColumn('scouting', 'coral_l2', {
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async up(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.addColumn(
|
|
||||||
'scouting',
|
|
||||||
'coral_l3',
|
|
||||||
{
|
|
||||||
type: Sequelize.DataTypes.INTEGER,
|
|
||||||
},
|
|
||||||
{ transaction },
|
|
||||||
);
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async down(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.removeColumn('scouting', 'coral_l3', {
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async up(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.addColumn(
|
|
||||||
'scouting',
|
|
||||||
'coral_l4',
|
|
||||||
{
|
|
||||||
type: Sequelize.DataTypes.INTEGER,
|
|
||||||
},
|
|
||||||
{ transaction },
|
|
||||||
);
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async down(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.removeColumn('scouting', 'coral_l4', {
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async up(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.addColumn(
|
|
||||||
'scouting',
|
|
||||||
'algae_processor',
|
|
||||||
{
|
|
||||||
type: Sequelize.DataTypes.INTEGER,
|
|
||||||
},
|
|
||||||
{ transaction },
|
|
||||||
);
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async down(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.removeColumn('scouting', 'algae_processor', {
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async up(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.addColumn(
|
|
||||||
'scouting',
|
|
||||||
'algae_net',
|
|
||||||
{
|
|
||||||
type: Sequelize.DataTypes.INTEGER,
|
|
||||||
},
|
|
||||||
{ transaction },
|
|
||||||
);
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @param {QueryInterface} queryInterface
|
|
||||||
* @param {Sequelize} Sequelize
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
async down(queryInterface, Sequelize) {
|
|
||||||
/**
|
|
||||||
* @type {Transaction}
|
|
||||||
*/
|
|
||||||
const transaction = await queryInterface.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await queryInterface.removeColumn('scouting', 'algae_net', {
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (err) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1,73 +0,0 @@
|
|||||||
const config = require('../../config');
|
|
||||||
const providers = config.providers;
|
|
||||||
const crypto = require('crypto');
|
|
||||||
const bcrypt = require('bcrypt');
|
|
||||||
const moment = require('moment');
|
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
|
||||||
const scouting = sequelize.define(
|
|
||||||
'scouting',
|
|
||||||
{
|
|
||||||
id: {
|
|
||||||
type: DataTypes.UUID,
|
|
||||||
defaultValue: DataTypes.UUIDV4,
|
|
||||||
primaryKey: true,
|
|
||||||
},
|
|
||||||
|
|
||||||
team_number: {
|
|
||||||
type: DataTypes.INTEGER,
|
|
||||||
},
|
|
||||||
|
|
||||||
coral_l1: {
|
|
||||||
type: DataTypes.INTEGER,
|
|
||||||
},
|
|
||||||
|
|
||||||
coral_l2: {
|
|
||||||
type: DataTypes.INTEGER,
|
|
||||||
},
|
|
||||||
|
|
||||||
coral_l3: {
|
|
||||||
type: DataTypes.INTEGER,
|
|
||||||
},
|
|
||||||
|
|
||||||
coral_l4: {
|
|
||||||
type: DataTypes.INTEGER,
|
|
||||||
},
|
|
||||||
|
|
||||||
algae_processor: {
|
|
||||||
type: DataTypes.INTEGER,
|
|
||||||
},
|
|
||||||
|
|
||||||
algae_net: {
|
|
||||||
type: DataTypes.INTEGER,
|
|
||||||
},
|
|
||||||
|
|
||||||
importHash: {
|
|
||||||
type: DataTypes.STRING(255),
|
|
||||||
allowNull: true,
|
|
||||||
unique: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
timestamps: true,
|
|
||||||
paranoid: true,
|
|
||||||
freezeTableName: true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
scouting.associate = (db) => {
|
|
||||||
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
||||||
|
|
||||||
//end loop
|
|
||||||
|
|
||||||
db.scouting.belongsTo(db.users, {
|
|
||||||
as: 'createdBy',
|
|
||||||
});
|
|
||||||
|
|
||||||
db.scouting.belongsTo(db.users, {
|
|
||||||
as: 'updatedBy',
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return scouting;
|
|
||||||
};
|
|
||||||
@ -106,7 +106,6 @@ module.exports = {
|
|||||||
'tasks',
|
'tasks',
|
||||||
'roles',
|
'roles',
|
||||||
'permissions',
|
'permissions',
|
||||||
'scouting',
|
|
||||||
,
|
,
|
||||||
];
|
];
|
||||||
await queryInterface.bulkInsert(
|
await queryInterface.bulkInsert(
|
||||||
@ -687,31 +686,6 @@ primary key ("roles_permissionsId", "permissionId")
|
|||||||
permissionId: getId('DELETE_PERMISSIONS'),
|
permissionId: getId('DELETE_PERMISSIONS'),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
roles_permissionsId: getId('Administrator'),
|
|
||||||
permissionId: getId('CREATE_SCOUTING'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
roles_permissionsId: getId('Administrator'),
|
|
||||||
permissionId: getId('READ_SCOUTING'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
roles_permissionsId: getId('Administrator'),
|
|
||||||
permissionId: getId('UPDATE_SCOUTING'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
roles_permissionsId: getId('Administrator'),
|
|
||||||
permissionId: getId('DELETE_SCOUTING'),
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
{
|
||||||
createdAt,
|
createdAt,
|
||||||
updatedAt,
|
updatedAt,
|
||||||
|
|||||||
@ -9,8 +9,6 @@ const ScoutingData = db.scouting_data;
|
|||||||
|
|
||||||
const Tasks = db.tasks;
|
const Tasks = db.tasks;
|
||||||
|
|
||||||
const Scouting = db.scouting;
|
|
||||||
|
|
||||||
const EventsData = [
|
const EventsData = [
|
||||||
{
|
{
|
||||||
name: 'Regional Qualifiers',
|
name: 'Regional Qualifiers',
|
||||||
@ -41,16 +39,6 @@ const EventsData = [
|
|||||||
|
|
||||||
// type code here for "relation_many" field
|
// type code here for "relation_many" field
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
|
||||||
name: 'International Expo',
|
|
||||||
|
|
||||||
start_date: new Date('2024-03-25T11:00:00Z'),
|
|
||||||
|
|
||||||
end_date: new Date('2024-03-27T20:00:00Z'),
|
|
||||||
|
|
||||||
// type code here for "relation_many" field
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const RobotsData = [
|
const RobotsData = [
|
||||||
@ -77,14 +65,6 @@ const RobotsData = [
|
|||||||
|
|
||||||
// type code here for "relation_many" field
|
// type code here for "relation_many" field
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
|
||||||
name: 'RoboEagle',
|
|
||||||
|
|
||||||
description: 'A versatile robot capable of performing complex tasks.',
|
|
||||||
|
|
||||||
// type code here for "relation_many" field
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const ScoutingDataData = [
|
const ScoutingDataData = [
|
||||||
@ -117,16 +97,6 @@ const ScoutingDataData = [
|
|||||||
|
|
||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
|
||||||
match_number: '004',
|
|
||||||
|
|
||||||
team_name: 'CircuitBreakers',
|
|
||||||
|
|
||||||
score: 88,
|
|
||||||
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const TasksData = [
|
const TasksData = [
|
||||||
@ -139,7 +109,7 @@ const TasksData = [
|
|||||||
|
|
||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
status: 'completed',
|
status: 'in_progress',
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -151,7 +121,7 @@ const TasksData = [
|
|||||||
|
|
||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
status: 'completed',
|
status: 'pending',
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -163,85 +133,7 @@ const TasksData = [
|
|||||||
|
|
||||||
// type code here for "relation_one" field
|
// type code here for "relation_one" field
|
||||||
|
|
||||||
status: 'in_progress',
|
status: 'pending',
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
title: 'Assemble Chassis',
|
|
||||||
|
|
||||||
description: 'Assemble the main chassis of the robot.',
|
|
||||||
|
|
||||||
due_date: new Date('2023-11-30T14:00:00Z'),
|
|
||||||
|
|
||||||
// type code here for "relation_one" field
|
|
||||||
|
|
||||||
status: 'completed',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const ScoutingData = [
|
|
||||||
{
|
|
||||||
team_number: 1,
|
|
||||||
|
|
||||||
coral_l1: 8,
|
|
||||||
|
|
||||||
coral_l2: 9,
|
|
||||||
|
|
||||||
coral_l3: 3,
|
|
||||||
|
|
||||||
coral_l4: 8,
|
|
||||||
|
|
||||||
algae_processor: 1,
|
|
||||||
|
|
||||||
algae_net: 3,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
team_number: 2,
|
|
||||||
|
|
||||||
coral_l1: 1,
|
|
||||||
|
|
||||||
coral_l2: 3,
|
|
||||||
|
|
||||||
coral_l3: 5,
|
|
||||||
|
|
||||||
coral_l4: 2,
|
|
||||||
|
|
||||||
algae_processor: 9,
|
|
||||||
|
|
||||||
algae_net: 8,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
team_number: 7,
|
|
||||||
|
|
||||||
coral_l1: 9,
|
|
||||||
|
|
||||||
coral_l2: 4,
|
|
||||||
|
|
||||||
coral_l3: 2,
|
|
||||||
|
|
||||||
coral_l4: 3,
|
|
||||||
|
|
||||||
algae_processor: 5,
|
|
||||||
|
|
||||||
algae_net: 6,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
team_number: 6,
|
|
||||||
|
|
||||||
coral_l1: 4,
|
|
||||||
|
|
||||||
coral_l2: 2,
|
|
||||||
|
|
||||||
coral_l3: 1,
|
|
||||||
|
|
||||||
coral_l4: 6,
|
|
||||||
|
|
||||||
algae_processor: 2,
|
|
||||||
|
|
||||||
algae_net: 3,
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -284,17 +176,6 @@ async function associateScoutingDatumWithSubmitted_by() {
|
|||||||
if (ScoutingDatum2?.setSubmitted_by) {
|
if (ScoutingDatum2?.setSubmitted_by) {
|
||||||
await ScoutingDatum2.setSubmitted_by(relatedSubmitted_by2);
|
await ScoutingDatum2.setSubmitted_by(relatedSubmitted_by2);
|
||||||
}
|
}
|
||||||
|
|
||||||
const relatedSubmitted_by3 = await Users.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Users.count())),
|
|
||||||
});
|
|
||||||
const ScoutingDatum3 = await ScoutingData.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 3,
|
|
||||||
});
|
|
||||||
if (ScoutingDatum3?.setSubmitted_by) {
|
|
||||||
await ScoutingDatum3.setSubmitted_by(relatedSubmitted_by3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function associateTaskWithAssigned_to() {
|
async function associateTaskWithAssigned_to() {
|
||||||
@ -330,17 +211,6 @@ async function associateTaskWithAssigned_to() {
|
|||||||
if (Task2?.setAssigned_to) {
|
if (Task2?.setAssigned_to) {
|
||||||
await Task2.setAssigned_to(relatedAssigned_to2);
|
await Task2.setAssigned_to(relatedAssigned_to2);
|
||||||
}
|
}
|
||||||
|
|
||||||
const relatedAssigned_to3 = await Users.findOne({
|
|
||||||
offset: Math.floor(Math.random() * (await Users.count())),
|
|
||||||
});
|
|
||||||
const Task3 = await Tasks.findOne({
|
|
||||||
order: [['id', 'ASC']],
|
|
||||||
offset: 3,
|
|
||||||
});
|
|
||||||
if (Task3?.setAssigned_to) {
|
|
||||||
await Task3.setAssigned_to(relatedAssigned_to3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@ -353,8 +223,6 @@ module.exports = {
|
|||||||
|
|
||||||
await Tasks.bulkCreate(TasksData);
|
await Tasks.bulkCreate(TasksData);
|
||||||
|
|
||||||
await Scouting.bulkCreate(ScoutingData);
|
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
// Similar logic for "relation_many"
|
// Similar logic for "relation_many"
|
||||||
|
|
||||||
@ -376,7 +244,5 @@ module.exports = {
|
|||||||
await queryInterface.bulkDelete('scouting_data', null, {});
|
await queryInterface.bulkDelete('scouting_data', null, {});
|
||||||
|
|
||||||
await queryInterface.bulkDelete('tasks', null, {});
|
await queryInterface.bulkDelete('tasks', null, {});
|
||||||
|
|
||||||
await queryInterface.bulkDelete('scouting', null, {});
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,87 +0,0 @@
|
|||||||
const { v4: uuid } = require('uuid');
|
|
||||||
const db = require('../models');
|
|
||||||
const Sequelize = require('sequelize');
|
|
||||||
const config = require('../../config');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
/**
|
|
||||||
* @param{import("sequelize").QueryInterface} queryInterface
|
|
||||||
* @return {Promise<void>}
|
|
||||||
*/
|
|
||||||
async up(queryInterface) {
|
|
||||||
const createdAt = new Date();
|
|
||||||
const updatedAt = new Date();
|
|
||||||
|
|
||||||
/** @type {Map<string, string>} */
|
|
||||||
const idMap = new Map();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} key
|
|
||||||
* @return {string}
|
|
||||||
*/
|
|
||||||
function getId(key) {
|
|
||||||
if (idMap.has(key)) {
|
|
||||||
return idMap.get(key);
|
|
||||||
}
|
|
||||||
const id = uuid();
|
|
||||||
idMap.set(key, id);
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} name
|
|
||||||
*/
|
|
||||||
function createPermissions(name) {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
id: getId(`CREATE_${name.toUpperCase()}`),
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
name: `CREATE_${name.toUpperCase()}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: getId(`READ_${name.toUpperCase()}`),
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
name: `READ_${name.toUpperCase()}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: getId(`UPDATE_${name.toUpperCase()}`),
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
name: `UPDATE_${name.toUpperCase()}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: getId(`DELETE_${name.toUpperCase()}`),
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
name: `DELETE_${name.toUpperCase()}`,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
const entities = ['scouting'];
|
|
||||||
|
|
||||||
const createdPermissions = entities.flatMap(createPermissions);
|
|
||||||
|
|
||||||
// Add permissions to database
|
|
||||||
await queryInterface.bulkInsert('permissions', createdPermissions);
|
|
||||||
// Get permissions ids
|
|
||||||
const permissionsIds = createdPermissions.map((p) => p.id);
|
|
||||||
// Get admin role
|
|
||||||
const adminRole = await db.roles.findOne({
|
|
||||||
where: { name: config.roles.admin },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (adminRole) {
|
|
||||||
// Add permissions to admin role if it exists
|
|
||||||
await adminRole.addPermissions(permissionsIds);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
down: async (queryInterface, Sequelize) => {
|
|
||||||
await queryInterface.bulkDelete(
|
|
||||||
'permissions',
|
|
||||||
entities.flatMap(createPermissions),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -17,8 +17,6 @@ const pexelsRoutes = require('./routes/pexels');
|
|||||||
|
|
||||||
const openaiRoutes = require('./routes/openai');
|
const openaiRoutes = require('./routes/openai');
|
||||||
|
|
||||||
const chatbotRoutes = require('./routes/chatbot');
|
|
||||||
|
|
||||||
const contactFormRoutes = require('./routes/contactForm');
|
const contactFormRoutes = require('./routes/contactForm');
|
||||||
|
|
||||||
const usersRoutes = require('./routes/users');
|
const usersRoutes = require('./routes/users');
|
||||||
@ -35,8 +33,6 @@ const rolesRoutes = require('./routes/roles');
|
|||||||
|
|
||||||
const permissionsRoutes = require('./routes/permissions');
|
const permissionsRoutes = require('./routes/permissions');
|
||||||
|
|
||||||
const scoutingRoutes = require('./routes/scouting');
|
|
||||||
|
|
||||||
const getBaseUrl = (url) => {
|
const getBaseUrl = (url) => {
|
||||||
if (!url) return '';
|
if (!url) return '';
|
||||||
return url.endsWith('/api') ? url.slice(0, -4) : url;
|
return url.endsWith('/api') ? url.slice(0, -4) : url;
|
||||||
@ -144,19 +140,11 @@ app.use(
|
|||||||
permissionsRoutes,
|
permissionsRoutes,
|
||||||
);
|
);
|
||||||
|
|
||||||
app.use(
|
|
||||||
'/api/scouting',
|
|
||||||
passport.authenticate('jwt', { session: false }),
|
|
||||||
scoutingRoutes,
|
|
||||||
);
|
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
'/api/openai',
|
'/api/openai',
|
||||||
passport.authenticate('jwt', { session: false }),
|
passport.authenticate('jwt', { session: false }),
|
||||||
openaiRoutes,
|
openaiRoutes,
|
||||||
);
|
);
|
||||||
app.use('/api/chatbot', chatbotRoutes);
|
|
||||||
|
|
||||||
|
|
||||||
app.use('/api/contact-form', contactFormRoutes);
|
app.use('/api/contact-form', contactFormRoutes);
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
const express = require('express');
|
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
// Simple in-house chatbot endpoint
|
|
||||||
router.post('/', (req, res) => {
|
|
||||||
const { text } = req.body;
|
|
||||||
if (!text) {
|
|
||||||
return res.status(400).json({ error: 'No message text provided.' });
|
|
||||||
}
|
|
||||||
// Echo back or implement simple rules here
|
|
||||||
const reply = `Bot: You said \"${text}\"`;
|
|
||||||
res.json({ reply });
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = router;
|
|
||||||
@ -6,10 +6,21 @@ const fetch = require('node-fetch');
|
|||||||
const KEY = pexelsKey;
|
const KEY = pexelsKey;
|
||||||
|
|
||||||
router.get('/image', async (req, res) => {
|
router.get('/image', async (req, res) => {
|
||||||
// Return static Wix image instead of Pexels
|
const headers = {
|
||||||
res.status(200).json({
|
Authorization: `${KEY}`,
|
||||||
src: 'https://static.wixstatic.com/media/42b9b7_87daee7014234d78a8a0766bd8d906bd~mv2.jpeg/v1/crop/x_0,y_186,w_768,h_652/fill/w_768,h_652,al_c,q_85,enc_avif,quality_auto/WhatsApp%20Image%202023-11-07%20at%2019_31_00.jpeg'
|
};
|
||||||
});
|
const query = pexelsQuery || 'nature';
|
||||||
|
const orientation = 'portrait';
|
||||||
|
const perPage = 1;
|
||||||
|
const url = `https://api.pexels.com/v1/search?query=${query}&orientation=${orientation}&per_page=${perPage}&page=1`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(url, { headers });
|
||||||
|
const data = await response.json();
|
||||||
|
res.status(200).json(data.photos[0]);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(200).json({ error: 'Failed to fetch image' });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/video', async (req, res) => {
|
router.get('/video', async (req, res) => {
|
||||||
@ -30,21 +41,66 @@ router.get('/video', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Return the user-specified static images in random order for all galleries
|
router.get('/multiple-images', async (req, res) => {
|
||||||
router.get('/multiple-images', (req, res) => {
|
const headers = {
|
||||||
const images = [
|
Authorization: `${KEY}`,
|
||||||
{ src: 'https://static.wixstatic.com/media/42b9b7_87daee7014234d78a8a0766bd8d906bd~mv2.jpeg/v1/crop/x_0,y_186,w_768,h_652/fill/w_768,h_652,al_c,q_85,enc_avif,quality_auto/WhatsApp%20Image%202023-11-07%20at%2019_31_00.jpeg', photographer: '', photographer_url: '' },
|
};
|
||||||
{ src: 'https://static.wixstatic.com/media/42b9b7_3e6e0cf2e71f4fca8c12705c35df1d61~mv2.jpg/v1/crop/x_59,y_0,w_905,h_768/fill/w_850,h_721,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/D29C232E-F61F-46B2-AF8C-1E29C87270C8_L0_001%20(1).jpg', photographer: '', photographer_url: '' },
|
|
||||||
{ src: 'https://static.wixstatic.com/media/42b9b7_b26e4585851c4e60a32d892baff6ca4e~mv2.png/v1/fill/w_529,h_678,al_c,lg_1,q_85,enc_avif,quality_auto/42b9b7_b26e4585851c4e60a32d892baff6ca4e~mv2.png', photographer: '', photographer_url: '' }
|
|
||||||
];
|
|
||||||
|
|
||||||
// Shuffle the images array
|
const queries = req.query.queries
|
||||||
for (let i = images.length - 1; i > 0; i--) {
|
? req.query.queries.split(',')
|
||||||
const j = Math.floor(Math.random() * (i + 1));
|
: ['home', 'apple', 'pizza', 'mountains', 'cat'];
|
||||||
[images[i], images[j]] = [images[j], images[i]];
|
const orientation = 'square';
|
||||||
}
|
const perPage = 1;
|
||||||
|
|
||||||
res.json(images);
|
const fallbackImage = {
|
||||||
|
src: 'https://images.pexels.com/photos/8199252/pexels-photo-8199252.jpeg',
|
||||||
|
photographer: 'Yan Krukau',
|
||||||
|
photographer_url: 'https://www.pexels.com/@yankrukov',
|
||||||
|
};
|
||||||
|
const fetchFallbackImage = async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetch('https://picsum.photos/600');
|
||||||
|
return {
|
||||||
|
src: response.url,
|
||||||
|
photographer: 'Random Picsum',
|
||||||
|
photographer_url: 'https://picsum.photos/',
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return fallbackImage;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const fetchImage = async (query) => {
|
||||||
|
const url = `https://api.pexels.com/v1/search?query=${query}&orientation=${orientation}&per_page=${perPage}&page=1`;
|
||||||
|
const response = await fetch(url, { headers });
|
||||||
|
const data = await response.json();
|
||||||
|
return data.photos[0] || null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const imagePromises = queries.map((query) => fetchImage(query));
|
||||||
|
const imagesResults = await Promise.allSettled(imagePromises);
|
||||||
|
|
||||||
|
const formattedImages = await Promise.all(
|
||||||
|
imagesResults.map(async (result) => {
|
||||||
|
if (result.status === 'fulfilled' && result.value) {
|
||||||
|
const image = result.value;
|
||||||
|
return {
|
||||||
|
src: image.src?.original || fallbackImage.src,
|
||||||
|
photographer: image.photographer || fallbackImage.photographer,
|
||||||
|
photographer_url:
|
||||||
|
image.photographer_url || fallbackImage.photographer_url,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const fallback = await fetchFallbackImage();
|
||||||
|
return {
|
||||||
|
src: fallback.src || '',
|
||||||
|
photographer: fallback.photographer || 'Unknown',
|
||||||
|
photographer_url: fallback.photographer_url || '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
res.json(formattedImages);
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
@ -1,465 +0,0 @@
|
|||||||
const express = require('express');
|
|
||||||
|
|
||||||
const ScoutingService = require('../services/scouting');
|
|
||||||
const ScoutingDBApi = require('../db/api/scouting');
|
|
||||||
const wrapAsync = require('../helpers').wrapAsync;
|
|
||||||
|
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
const { parse } = require('json2csv');
|
|
||||||
|
|
||||||
const { checkCrudPermissions } = require('../middlewares/check-permissions');
|
|
||||||
|
|
||||||
router.use(checkCrudPermissions('scouting'));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* components:
|
|
||||||
* schemas:
|
|
||||||
* Scouting:
|
|
||||||
* type: object
|
|
||||||
* properties:
|
|
||||||
|
|
||||||
* team_number:
|
|
||||||
* type: integer
|
|
||||||
* format: int64
|
|
||||||
* coral_l1:
|
|
||||||
* type: integer
|
|
||||||
* format: int64
|
|
||||||
* coral_l2:
|
|
||||||
* type: integer
|
|
||||||
* format: int64
|
|
||||||
* coral_l3:
|
|
||||||
* type: integer
|
|
||||||
* format: int64
|
|
||||||
* coral_l4:
|
|
||||||
* type: integer
|
|
||||||
* format: int64
|
|
||||||
* algae_processor:
|
|
||||||
* type: integer
|
|
||||||
* format: int64
|
|
||||||
* algae_net:
|
|
||||||
* type: integer
|
|
||||||
* format: int64
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* tags:
|
|
||||||
* name: Scouting
|
|
||||||
* description: The Scouting managing API
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/scouting:
|
|
||||||
* post:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Scouting]
|
|
||||||
* summary: Add new item
|
|
||||||
* description: Add new item
|
|
||||||
* requestBody:
|
|
||||||
* required: true
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* properties:
|
|
||||||
* data:
|
|
||||||
* description: Data of the updated item
|
|
||||||
* type: object
|
|
||||||
* $ref: "#/components/schemas/Scouting"
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: The item was successfully added
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* $ref: "#/components/schemas/Scouting"
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 405:
|
|
||||||
* description: Invalid input data
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.post(
|
|
||||||
'/',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
const referer =
|
|
||||||
req.headers.referer ||
|
|
||||||
`${req.protocol}://${req.hostname}${req.originalUrl}`;
|
|
||||||
const link = new URL(referer);
|
|
||||||
await ScoutingService.create(
|
|
||||||
req.body.data,
|
|
||||||
req.currentUser,
|
|
||||||
true,
|
|
||||||
link.host,
|
|
||||||
);
|
|
||||||
const payload = true;
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/budgets/bulk-import:
|
|
||||||
* post:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Scouting]
|
|
||||||
* summary: Bulk import items
|
|
||||||
* description: Bulk import items
|
|
||||||
* requestBody:
|
|
||||||
* required: true
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* properties:
|
|
||||||
* data:
|
|
||||||
* description: Data of the updated items
|
|
||||||
* type: array
|
|
||||||
* items:
|
|
||||||
* $ref: "#/components/schemas/Scouting"
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: The items were successfully imported
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* $ref: "#/components/schemas/Scouting"
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 405:
|
|
||||||
* description: Invalid input data
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
router.post(
|
|
||||||
'/bulk-import',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
const referer =
|
|
||||||
req.headers.referer ||
|
|
||||||
`${req.protocol}://${req.hostname}${req.originalUrl}`;
|
|
||||||
const link = new URL(referer);
|
|
||||||
await ScoutingService.bulkImport(req, res, true, link.host);
|
|
||||||
const payload = true;
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/scouting/{id}:
|
|
||||||
* put:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Scouting]
|
|
||||||
* summary: Update the data of the selected item
|
|
||||||
* description: Update the data of the selected item
|
|
||||||
* parameters:
|
|
||||||
* - in: path
|
|
||||||
* name: id
|
|
||||||
* description: Item ID to update
|
|
||||||
* required: true
|
|
||||||
* schema:
|
|
||||||
* type: string
|
|
||||||
* requestBody:
|
|
||||||
* description: Set new item data
|
|
||||||
* required: true
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* properties:
|
|
||||||
* id:
|
|
||||||
* description: ID of the updated item
|
|
||||||
* type: string
|
|
||||||
* data:
|
|
||||||
* description: Data of the updated item
|
|
||||||
* type: object
|
|
||||||
* $ref: "#/components/schemas/Scouting"
|
|
||||||
* required:
|
|
||||||
* - id
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: The item data was successfully updated
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* $ref: "#/components/schemas/Scouting"
|
|
||||||
* 400:
|
|
||||||
* description: Invalid ID supplied
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 404:
|
|
||||||
* description: Item not found
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.put(
|
|
||||||
'/:id',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
await ScoutingService.update(req.body.data, req.body.id, req.currentUser);
|
|
||||||
const payload = true;
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/scouting/{id}:
|
|
||||||
* delete:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Scouting]
|
|
||||||
* summary: Delete the selected item
|
|
||||||
* description: Delete the selected item
|
|
||||||
* parameters:
|
|
||||||
* - in: path
|
|
||||||
* name: id
|
|
||||||
* description: Item ID to delete
|
|
||||||
* required: true
|
|
||||||
* schema:
|
|
||||||
* type: string
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: The item was successfully deleted
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* $ref: "#/components/schemas/Scouting"
|
|
||||||
* 400:
|
|
||||||
* description: Invalid ID supplied
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 404:
|
|
||||||
* description: Item not found
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.delete(
|
|
||||||
'/:id',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
await ScoutingService.remove(req.params.id, req.currentUser);
|
|
||||||
const payload = true;
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/scouting/deleteByIds:
|
|
||||||
* post:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Scouting]
|
|
||||||
* summary: Delete the selected item list
|
|
||||||
* description: Delete the selected item list
|
|
||||||
* requestBody:
|
|
||||||
* required: true
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* properties:
|
|
||||||
* ids:
|
|
||||||
* description: IDs of the updated items
|
|
||||||
* type: array
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: The items was successfully deleted
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* $ref: "#/components/schemas/Scouting"
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 404:
|
|
||||||
* description: Items not found
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.post(
|
|
||||||
'/deleteByIds',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
await ScoutingService.deleteByIds(req.body.data, req.currentUser);
|
|
||||||
const payload = true;
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/scouting:
|
|
||||||
* get:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Scouting]
|
|
||||||
* summary: Get all scouting
|
|
||||||
* description: Get all scouting
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: Scouting list successfully received
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: array
|
|
||||||
* items:
|
|
||||||
* $ref: "#/components/schemas/Scouting"
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 404:
|
|
||||||
* description: Data not found
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.get(
|
|
||||||
'/',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
const filetype = req.query.filetype;
|
|
||||||
|
|
||||||
const currentUser = req.currentUser;
|
|
||||||
const payload = await ScoutingDBApi.findAll(req.query, { currentUser });
|
|
||||||
if (filetype && filetype === 'csv') {
|
|
||||||
const fields = [
|
|
||||||
'id',
|
|
||||||
'team_number',
|
|
||||||
'coral_l1',
|
|
||||||
'coral_l2',
|
|
||||||
'coral_l3',
|
|
||||||
'coral_l4',
|
|
||||||
'algae_processor',
|
|
||||||
'algae_net',
|
|
||||||
];
|
|
||||||
const opts = { fields };
|
|
||||||
try {
|
|
||||||
const csv = parse(payload.rows, opts);
|
|
||||||
res.status(200).attachment(csv);
|
|
||||||
res.send(csv);
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/scouting/count:
|
|
||||||
* get:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Scouting]
|
|
||||||
* summary: Count all scouting
|
|
||||||
* description: Count all scouting
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: Scouting count successfully received
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: array
|
|
||||||
* items:
|
|
||||||
* $ref: "#/components/schemas/Scouting"
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 404:
|
|
||||||
* description: Data not found
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.get(
|
|
||||||
'/count',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
const currentUser = req.currentUser;
|
|
||||||
const payload = await ScoutingDBApi.findAll(req.query, null, {
|
|
||||||
countOnly: true,
|
|
||||||
currentUser,
|
|
||||||
});
|
|
||||||
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/scouting/autocomplete:
|
|
||||||
* get:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Scouting]
|
|
||||||
* summary: Find all scouting that match search criteria
|
|
||||||
* description: Find all scouting that match search criteria
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: Scouting list successfully received
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: array
|
|
||||||
* items:
|
|
||||||
* $ref: "#/components/schemas/Scouting"
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 404:
|
|
||||||
* description: Data not found
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.get('/autocomplete', async (req, res) => {
|
|
||||||
const payload = await ScoutingDBApi.findAllAutocomplete(
|
|
||||||
req.query.query,
|
|
||||||
req.query.limit,
|
|
||||||
req.query.offset,
|
|
||||||
);
|
|
||||||
|
|
||||||
res.status(200).send(payload);
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /api/scouting/{id}:
|
|
||||||
* get:
|
|
||||||
* security:
|
|
||||||
* - bearerAuth: []
|
|
||||||
* tags: [Scouting]
|
|
||||||
* summary: Get selected item
|
|
||||||
* description: Get selected item
|
|
||||||
* parameters:
|
|
||||||
* - in: path
|
|
||||||
* name: id
|
|
||||||
* description: ID of item to get
|
|
||||||
* required: true
|
|
||||||
* schema:
|
|
||||||
* type: string
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: Selected item successfully received
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* $ref: "#/components/schemas/Scouting"
|
|
||||||
* 400:
|
|
||||||
* description: Invalid ID supplied
|
|
||||||
* 401:
|
|
||||||
* $ref: "#/components/responses/UnauthorizedError"
|
|
||||||
* 404:
|
|
||||||
* description: Item not found
|
|
||||||
* 500:
|
|
||||||
* description: Some server error
|
|
||||||
*/
|
|
||||||
router.get(
|
|
||||||
'/:id',
|
|
||||||
wrapAsync(async (req, res) => {
|
|
||||||
const payload = await ScoutingDBApi.findBy({ id: req.params.id });
|
|
||||||
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
router.use('/', require('../helpers').commonErrorHandler);
|
|
||||||
|
|
||||||
module.exports = router;
|
|
||||||
@ -1,114 +0,0 @@
|
|||||||
const db = require('../db/models');
|
|
||||||
const ScoutingDBApi = require('../db/api/scouting');
|
|
||||||
const processFile = require('../middlewares/upload');
|
|
||||||
const ValidationError = require('./notifications/errors/validation');
|
|
||||||
const csv = require('csv-parser');
|
|
||||||
const axios = require('axios');
|
|
||||||
const config = require('../config');
|
|
||||||
const stream = require('stream');
|
|
||||||
|
|
||||||
module.exports = class ScoutingService {
|
|
||||||
static async create(data, currentUser) {
|
|
||||||
const transaction = await db.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
await ScoutingDBApi.create(data, {
|
|
||||||
currentUser,
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (error) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async bulkImport(req, res, sendInvitationEmails = true, host) {
|
|
||||||
const transaction = await db.sequelize.transaction();
|
|
||||||
|
|
||||||
try {
|
|
||||||
await processFile(req, res);
|
|
||||||
const bufferStream = new stream.PassThrough();
|
|
||||||
const results = [];
|
|
||||||
|
|
||||||
await bufferStream.end(Buffer.from(req.file.buffer, 'utf-8')); // convert Buffer to Stream
|
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
bufferStream
|
|
||||||
.pipe(csv())
|
|
||||||
.on('data', (data) => results.push(data))
|
|
||||||
.on('end', async () => {
|
|
||||||
console.log('CSV results', results);
|
|
||||||
resolve();
|
|
||||||
})
|
|
||||||
.on('error', (error) => reject(error));
|
|
||||||
});
|
|
||||||
|
|
||||||
await ScoutingDBApi.bulkImport(results, {
|
|
||||||
transaction,
|
|
||||||
ignoreDuplicates: true,
|
|
||||||
validate: true,
|
|
||||||
currentUser: req.currentUser,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (error) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async update(data, id, currentUser) {
|
|
||||||
const transaction = await db.sequelize.transaction();
|
|
||||||
try {
|
|
||||||
let scouting = await ScoutingDBApi.findBy({ id }, { transaction });
|
|
||||||
|
|
||||||
if (!scouting) {
|
|
||||||
throw new ValidationError('scoutingNotFound');
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedScouting = await ScoutingDBApi.update(id, data, {
|
|
||||||
currentUser,
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
return updatedScouting;
|
|
||||||
} catch (error) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async deleteByIds(ids, currentUser) {
|
|
||||||
const transaction = await db.sequelize.transaction();
|
|
||||||
|
|
||||||
try {
|
|
||||||
await ScoutingDBApi.deleteByIds(ids, {
|
|
||||||
currentUser,
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (error) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async remove(id, currentUser) {
|
|
||||||
const transaction = await db.sequelize.transaction();
|
|
||||||
|
|
||||||
try {
|
|
||||||
await ScoutingDBApi.remove(id, {
|
|
||||||
currentUser,
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
await transaction.commit();
|
|
||||||
} catch (error) {
|
|
||||||
await transaction.rollback();
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -53,22 +53,6 @@ module.exports = class SearchService {
|
|||||||
};
|
};
|
||||||
const columnsInt = {
|
const columnsInt = {
|
||||||
scouting_data: ['score'],
|
scouting_data: ['score'],
|
||||||
|
|
||||||
scouting: [
|
|
||||||
'team_number',
|
|
||||||
|
|
||||||
'coral_l1',
|
|
||||||
|
|
||||||
'coral_l2',
|
|
||||||
|
|
||||||
'coral_l3',
|
|
||||||
|
|
||||||
'coral_l4',
|
|
||||||
|
|
||||||
'algae_processor',
|
|
||||||
|
|
||||||
'algae_net',
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let allFoundRecords = [];
|
let allFoundRecords = [];
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
{}
|
|
||||||
@ -1,175 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import ImageField from '../ImageField';
|
|
||||||
import ListActionsPopover from '../ListActionsPopover';
|
|
||||||
import { useAppSelector } from '../../stores/hooks';
|
|
||||||
import dataFormatter from '../../helpers/dataFormatter';
|
|
||||||
import { Pagination } from '../Pagination';
|
|
||||||
import { saveFile } from '../../helpers/fileSaver';
|
|
||||||
import LoadingSpinner from '../LoadingSpinner';
|
|
||||||
import Link from 'next/link';
|
|
||||||
|
|
||||||
import { hasPermission } from '../../helpers/userPermissions';
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
scouting: any[];
|
|
||||||
loading: boolean;
|
|
||||||
onDelete: (id: string) => void;
|
|
||||||
currentPage: number;
|
|
||||||
numPages: number;
|
|
||||||
onPageChange: (page: number) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
const CardScouting = ({
|
|
||||||
scouting,
|
|
||||||
loading,
|
|
||||||
onDelete,
|
|
||||||
currentPage,
|
|
||||||
numPages,
|
|
||||||
onPageChange,
|
|
||||||
}: Props) => {
|
|
||||||
const asideScrollbarsStyle = useAppSelector(
|
|
||||||
(state) => state.style.asideScrollbarsStyle,
|
|
||||||
);
|
|
||||||
const bgColor = useAppSelector((state) => state.style.cardsColor);
|
|
||||||
const darkMode = useAppSelector((state) => state.style.darkMode);
|
|
||||||
const corners = useAppSelector((state) => state.style.corners);
|
|
||||||
const focusRing = useAppSelector((state) => state.style.focusRingColor);
|
|
||||||
|
|
||||||
const currentUser = useAppSelector((state) => state.auth.currentUser);
|
|
||||||
const hasUpdatePermission = hasPermission(currentUser, 'UPDATE_SCOUTING');
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={'p-4'}>
|
|
||||||
{loading && <LoadingSpinner />}
|
|
||||||
<ul
|
|
||||||
role='list'
|
|
||||||
className='grid grid-cols-1 gap-x-6 gap-y-8 lg:grid-cols-3 2xl:grid-cols-4 xl:gap-x-8'
|
|
||||||
>
|
|
||||||
{!loading &&
|
|
||||||
scouting.map((item, index) => (
|
|
||||||
<li
|
|
||||||
key={item.id}
|
|
||||||
className={`overflow-hidden ${
|
|
||||||
corners !== 'rounded-full' ? corners : 'rounded-3xl'
|
|
||||||
} border ${focusRing} border-gray-200 dark:border-dark-700 ${
|
|
||||||
darkMode ? 'aside-scrollbars-[slate]' : asideScrollbarsStyle
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className={`flex items-center ${bgColor} p-6 gap-x-4 border-b border-gray-900/5 bg-gray-50 dark:bg-dark-800 relative`}
|
|
||||||
>
|
|
||||||
<Link
|
|
||||||
href={`/scouting/scouting-view/?id=${item.id}`}
|
|
||||||
className='text-lg font-bold leading-6 line-clamp-1'
|
|
||||||
>
|
|
||||||
{item.team_number}
|
|
||||||
</Link>
|
|
||||||
|
|
||||||
<div className='ml-auto '>
|
|
||||||
<ListActionsPopover
|
|
||||||
onDelete={onDelete}
|
|
||||||
itemId={item.id}
|
|
||||||
pathEdit={`/scouting/scouting-edit/?id=${item.id}`}
|
|
||||||
pathView={`/scouting/scouting-view/?id=${item.id}`}
|
|
||||||
hasUpdatePermission={hasUpdatePermission}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<dl className='divide-y divide-gray-600 dark:divide-dark-700 px-6 py-4 text-sm leading-6 h-64 overflow-y-auto'>
|
|
||||||
<div className='flex justify-between gap-x-4 py-3'>
|
|
||||||
<dt className=' text-gray-500 dark:text-dark-600'>
|
|
||||||
Team number
|
|
||||||
</dt>
|
|
||||||
<dd className='flex items-start gap-x-2'>
|
|
||||||
<div className='font-medium line-clamp-4'>
|
|
||||||
{item.team_number}
|
|
||||||
</div>
|
|
||||||
</dd>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='flex justify-between gap-x-4 py-3'>
|
|
||||||
<dt className=' text-gray-500 dark:text-dark-600'>
|
|
||||||
Coral l1
|
|
||||||
</dt>
|
|
||||||
<dd className='flex items-start gap-x-2'>
|
|
||||||
<div className='font-medium line-clamp-4'>
|
|
||||||
{item.coral_l1}
|
|
||||||
</div>
|
|
||||||
</dd>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='flex justify-between gap-x-4 py-3'>
|
|
||||||
<dt className=' text-gray-500 dark:text-dark-600'>
|
|
||||||
Coral l2
|
|
||||||
</dt>
|
|
||||||
<dd className='flex items-start gap-x-2'>
|
|
||||||
<div className='font-medium line-clamp-4'>
|
|
||||||
{item.coral_l2}
|
|
||||||
</div>
|
|
||||||
</dd>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='flex justify-between gap-x-4 py-3'>
|
|
||||||
<dt className=' text-gray-500 dark:text-dark-600'>
|
|
||||||
Coral l3
|
|
||||||
</dt>
|
|
||||||
<dd className='flex items-start gap-x-2'>
|
|
||||||
<div className='font-medium line-clamp-4'>
|
|
||||||
{item.coral_l3}
|
|
||||||
</div>
|
|
||||||
</dd>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='flex justify-between gap-x-4 py-3'>
|
|
||||||
<dt className=' text-gray-500 dark:text-dark-600'>
|
|
||||||
Coral l4
|
|
||||||
</dt>
|
|
||||||
<dd className='flex items-start gap-x-2'>
|
|
||||||
<div className='font-medium line-clamp-4'>
|
|
||||||
{item.coral_l4}
|
|
||||||
</div>
|
|
||||||
</dd>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='flex justify-between gap-x-4 py-3'>
|
|
||||||
<dt className=' text-gray-500 dark:text-dark-600'>
|
|
||||||
Algae processor
|
|
||||||
</dt>
|
|
||||||
<dd className='flex items-start gap-x-2'>
|
|
||||||
<div className='font-medium line-clamp-4'>
|
|
||||||
{item.algae_processor}
|
|
||||||
</div>
|
|
||||||
</dd>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='flex justify-between gap-x-4 py-3'>
|
|
||||||
<dt className=' text-gray-500 dark:text-dark-600'>
|
|
||||||
Algae net
|
|
||||||
</dt>
|
|
||||||
<dd className='flex items-start gap-x-2'>
|
|
||||||
<div className='font-medium line-clamp-4'>
|
|
||||||
{item.algae_net}
|
|
||||||
</div>
|
|
||||||
</dd>
|
|
||||||
</div>
|
|
||||||
</dl>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
{!loading && scouting.length === 0 && (
|
|
||||||
<div className='col-span-full flex items-center justify-center h-40'>
|
|
||||||
<p className=''>No data to display</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</ul>
|
|
||||||
<div className={'flex items-center justify-center my-6'}>
|
|
||||||
<Pagination
|
|
||||||
currentPage={currentPage}
|
|
||||||
numPages={numPages}
|
|
||||||
setCurrentPage={onPageChange}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default CardScouting;
|
|
||||||
@ -1,121 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import CardBox from '../CardBox';
|
|
||||||
import ImageField from '../ImageField';
|
|
||||||
import dataFormatter from '../../helpers/dataFormatter';
|
|
||||||
import { saveFile } from '../../helpers/fileSaver';
|
|
||||||
import ListActionsPopover from '../ListActionsPopover';
|
|
||||||
import { useAppSelector } from '../../stores/hooks';
|
|
||||||
import { Pagination } from '../Pagination';
|
|
||||||
import LoadingSpinner from '../LoadingSpinner';
|
|
||||||
import Link from 'next/link';
|
|
||||||
|
|
||||||
import { hasPermission } from '../../helpers/userPermissions';
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
scouting: any[];
|
|
||||||
loading: boolean;
|
|
||||||
onDelete: (id: string) => void;
|
|
||||||
currentPage: number;
|
|
||||||
numPages: number;
|
|
||||||
onPageChange: (page: number) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
const ListScouting = ({
|
|
||||||
scouting,
|
|
||||||
loading,
|
|
||||||
onDelete,
|
|
||||||
currentPage,
|
|
||||||
numPages,
|
|
||||||
onPageChange,
|
|
||||||
}: Props) => {
|
|
||||||
const currentUser = useAppSelector((state) => state.auth.currentUser);
|
|
||||||
const hasUpdatePermission = hasPermission(currentUser, 'UPDATE_SCOUTING');
|
|
||||||
|
|
||||||
const corners = useAppSelector((state) => state.style.corners);
|
|
||||||
const bgColor = useAppSelector((state) => state.style.cardsColor);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className='relative overflow-x-auto p-4 space-y-4'>
|
|
||||||
{loading && <LoadingSpinner />}
|
|
||||||
{!loading &&
|
|
||||||
scouting.map((item) => (
|
|
||||||
<div key={item.id}>
|
|
||||||
<CardBox hasTable isList className={'rounded shadow-none'}>
|
|
||||||
<div
|
|
||||||
className={`flex ${bgColor} ${
|
|
||||||
corners !== 'rounded-full' ? corners : 'rounded-3xl'
|
|
||||||
} dark:bg-dark-900 border border-gray-600 items-center overflow-hidden`}
|
|
||||||
>
|
|
||||||
<Link
|
|
||||||
href={`/scouting/scouting-view/?id=${item.id}`}
|
|
||||||
className={
|
|
||||||
'flex-1 px-4 py-6 h-24 flex divide-x-2 divide-gray-600 items-center overflow-hidden`}> dark:divide-dark-700 overflow-x-auto'
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<div className={'flex-1 px-3'}>
|
|
||||||
<p className={'text-xs text-gray-500 '}>Team number</p>
|
|
||||||
<p className={'line-clamp-2'}>{item.team_number}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={'flex-1 px-3'}>
|
|
||||||
<p className={'text-xs text-gray-500 '}>Coral l1</p>
|
|
||||||
<p className={'line-clamp-2'}>{item.coral_l1}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={'flex-1 px-3'}>
|
|
||||||
<p className={'text-xs text-gray-500 '}>Coral l2</p>
|
|
||||||
<p className={'line-clamp-2'}>{item.coral_l2}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={'flex-1 px-3'}>
|
|
||||||
<p className={'text-xs text-gray-500 '}>Coral l3</p>
|
|
||||||
<p className={'line-clamp-2'}>{item.coral_l3}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={'flex-1 px-3'}>
|
|
||||||
<p className={'text-xs text-gray-500 '}>Coral l4</p>
|
|
||||||
<p className={'line-clamp-2'}>{item.coral_l4}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={'flex-1 px-3'}>
|
|
||||||
<p className={'text-xs text-gray-500 '}>
|
|
||||||
Algae processor
|
|
||||||
</p>
|
|
||||||
<p className={'line-clamp-2'}>{item.algae_processor}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={'flex-1 px-3'}>
|
|
||||||
<p className={'text-xs text-gray-500 '}>Algae net</p>
|
|
||||||
<p className={'line-clamp-2'}>{item.algae_net}</p>
|
|
||||||
</div>
|
|
||||||
</Link>
|
|
||||||
<ListActionsPopover
|
|
||||||
onDelete={onDelete}
|
|
||||||
itemId={item.id}
|
|
||||||
pathEdit={`/scouting/scouting-edit/?id=${item.id}`}
|
|
||||||
pathView={`/scouting/scouting-view/?id=${item.id}`}
|
|
||||||
hasUpdatePermission={hasUpdatePermission}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</CardBox>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
{!loading && scouting.length === 0 && (
|
|
||||||
<div className='col-span-full flex items-center justify-center h-40'>
|
|
||||||
<p className=''>No data to display</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className={'flex items-center justify-center my-6'}>
|
|
||||||
<Pagination
|
|
||||||
currentPage={currentPage}
|
|
||||||
numPages={numPages}
|
|
||||||
setCurrentPage={onPageChange}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ListScouting;
|
|
||||||
@ -1,484 +0,0 @@
|
|||||||
import React, { useEffect, useState, useMemo } from 'react';
|
|
||||||
import { createPortal } from 'react-dom';
|
|
||||||
import { ToastContainer, toast } from 'react-toastify';
|
|
||||||
import BaseButton from '../BaseButton';
|
|
||||||
import CardBoxModal from '../CardBoxModal';
|
|
||||||
import CardBox from '../CardBox';
|
|
||||||
import {
|
|
||||||
fetch,
|
|
||||||
update,
|
|
||||||
deleteItem,
|
|
||||||
setRefetch,
|
|
||||||
deleteItemsByIds,
|
|
||||||
} from '../../stores/scouting/scoutingSlice';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
|
||||||
import { useRouter } from 'next/router';
|
|
||||||
import { Field, Form, Formik } from 'formik';
|
|
||||||
import { DataGrid, GridColDef } from '@mui/x-data-grid';
|
|
||||||
import { loadColumns } from './configureScoutingCols';
|
|
||||||
import _ from 'lodash';
|
|
||||||
import dataFormatter from '../../helpers/dataFormatter';
|
|
||||||
import { dataGridStyles } from '../../styles';
|
|
||||||
|
|
||||||
const perPage = 10;
|
|
||||||
|
|
||||||
const TableSampleScouting = ({
|
|
||||||
filterItems,
|
|
||||||
setFilterItems,
|
|
||||||
filters,
|
|
||||||
showGrid,
|
|
||||||
}) => {
|
|
||||||
const notify = (type, msg) => toast(msg, { type, position: 'bottom-center' });
|
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
const pagesList = [];
|
|
||||||
const [id, setId] = useState(null);
|
|
||||||
const [currentPage, setCurrentPage] = useState(0);
|
|
||||||
const [filterRequest, setFilterRequest] = React.useState('');
|
|
||||||
const [columns, setColumns] = useState<GridColDef[]>([]);
|
|
||||||
const [selectedRows, setSelectedRows] = useState([]);
|
|
||||||
const [sortModel, setSortModel] = useState([
|
|
||||||
{
|
|
||||||
field: '',
|
|
||||||
sort: 'desc',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const {
|
|
||||||
scouting,
|
|
||||||
loading,
|
|
||||||
count,
|
|
||||||
notify: scoutingNotify,
|
|
||||||
refetch,
|
|
||||||
} = useAppSelector((state) => state.scouting);
|
|
||||||
const { currentUser } = useAppSelector((state) => state.auth);
|
|
||||||
const focusRing = useAppSelector((state) => state.style.focusRingColor);
|
|
||||||
const bgColor = useAppSelector((state) => state.style.bgLayoutColor);
|
|
||||||
const corners = useAppSelector((state) => state.style.corners);
|
|
||||||
const numPages =
|
|
||||||
Math.floor(count / perPage) === 0 ? 1 : Math.ceil(count / perPage);
|
|
||||||
for (let i = 0; i < numPages; i++) {
|
|
||||||
pagesList.push(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadData = async (page = currentPage, request = filterRequest) => {
|
|
||||||
if (page !== currentPage) setCurrentPage(page);
|
|
||||||
if (request !== filterRequest) setFilterRequest(request);
|
|
||||||
const { sort, field } = sortModel[0];
|
|
||||||
|
|
||||||
const query = `?page=${page}&limit=${perPage}${request}&sort=${sort}&field=${field}`;
|
|
||||||
dispatch(fetch({ limit: perPage, page, query }));
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (scoutingNotify.showNotification) {
|
|
||||||
notify(scoutingNotify.typeNotification, scoutingNotify.textNotification);
|
|
||||||
}
|
|
||||||
}, [scoutingNotify.showNotification]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!currentUser) return;
|
|
||||||
loadData();
|
|
||||||
}, [sortModel, currentUser]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (refetch) {
|
|
||||||
loadData(0);
|
|
||||||
dispatch(setRefetch(false));
|
|
||||||
}
|
|
||||||
}, [refetch, dispatch]);
|
|
||||||
|
|
||||||
const [isModalInfoActive, setIsModalInfoActive] = useState(false);
|
|
||||||
const [isModalTrashActive, setIsModalTrashActive] = useState(false);
|
|
||||||
|
|
||||||
const handleModalAction = () => {
|
|
||||||
setIsModalInfoActive(false);
|
|
||||||
setIsModalTrashActive(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDeleteModalAction = (id: string) => {
|
|
||||||
setId(id);
|
|
||||||
setIsModalTrashActive(true);
|
|
||||||
};
|
|
||||||
const handleDeleteAction = async () => {
|
|
||||||
if (id) {
|
|
||||||
await dispatch(deleteItem(id));
|
|
||||||
await loadData(0);
|
|
||||||
setIsModalTrashActive(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const generateFilterRequests = useMemo(() => {
|
|
||||||
let request = '&';
|
|
||||||
filterItems.forEach((item) => {
|
|
||||||
const isRangeFilter = filters.find(
|
|
||||||
(filter) =>
|
|
||||||
filter.title === item.fields.selectedField &&
|
|
||||||
(filter.number || filter.date),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isRangeFilter) {
|
|
||||||
const from = item.fields.filterValueFrom;
|
|
||||||
const to = item.fields.filterValueTo;
|
|
||||||
if (from) {
|
|
||||||
request += `${item.fields.selectedField}Range=${from}&`;
|
|
||||||
}
|
|
||||||
if (to) {
|
|
||||||
request += `${item.fields.selectedField}Range=${to}&`;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const value = item.fields.filterValue;
|
|
||||||
if (value) {
|
|
||||||
request += `${item.fields.selectedField}=${value}&`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return request;
|
|
||||||
}, [filterItems, filters]);
|
|
||||||
|
|
||||||
const deleteFilter = (value) => {
|
|
||||||
const newItems = filterItems.filter((item) => item.id !== value);
|
|
||||||
|
|
||||||
if (newItems.length) {
|
|
||||||
setFilterItems(newItems);
|
|
||||||
} else {
|
|
||||||
loadData(0, '');
|
|
||||||
|
|
||||||
setFilterItems(newItems);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSubmit = () => {
|
|
||||||
loadData(0, generateFilterRequests);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleChange = (id) => (e) => {
|
|
||||||
const value = e.target.value;
|
|
||||||
const name = e.target.name;
|
|
||||||
|
|
||||||
setFilterItems(
|
|
||||||
filterItems.map((item) => {
|
|
||||||
if (item.id !== id) return item;
|
|
||||||
if (name === 'selectedField') return { id, fields: { [name]: value } };
|
|
||||||
|
|
||||||
return { id, fields: { ...item.fields, [name]: value } };
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleReset = () => {
|
|
||||||
setFilterItems([]);
|
|
||||||
loadData(0, '');
|
|
||||||
};
|
|
||||||
|
|
||||||
const onPageChange = (page: number) => {
|
|
||||||
loadData(page);
|
|
||||||
setCurrentPage(page);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!currentUser) return;
|
|
||||||
|
|
||||||
loadColumns(handleDeleteModalAction, `scouting`, currentUser).then(
|
|
||||||
(newCols) => setColumns(newCols),
|
|
||||||
);
|
|
||||||
}, [currentUser]);
|
|
||||||
|
|
||||||
const handleTableSubmit = async (id: string, data) => {
|
|
||||||
if (!_.isEmpty(data)) {
|
|
||||||
await dispatch(update({ id, data }))
|
|
||||||
.unwrap()
|
|
||||||
.then((res) => res)
|
|
||||||
.catch((err) => {
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onDeleteRows = async (selectedRows) => {
|
|
||||||
await dispatch(deleteItemsByIds(selectedRows));
|
|
||||||
await loadData(0);
|
|
||||||
};
|
|
||||||
|
|
||||||
const controlClasses =
|
|
||||||
'w-full py-2 px-2 my-2 rounded dark:placeholder-gray-400 ' +
|
|
||||||
` ${bgColor} ${focusRing} ${corners} ` +
|
|
||||||
'dark:bg-slate-800 border';
|
|
||||||
|
|
||||||
const dataGrid = (
|
|
||||||
<div className='relative overflow-x-auto'>
|
|
||||||
<DataGrid
|
|
||||||
autoHeight
|
|
||||||
rowHeight={64}
|
|
||||||
sx={dataGridStyles}
|
|
||||||
className={'datagrid--table'}
|
|
||||||
getRowClassName={() => `datagrid--row`}
|
|
||||||
rows={scouting ?? []}
|
|
||||||
columns={columns}
|
|
||||||
initialState={{
|
|
||||||
pagination: {
|
|
||||||
paginationModel: {
|
|
||||||
pageSize: 10,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
disableRowSelectionOnClick
|
|
||||||
onProcessRowUpdateError={(params) => {
|
|
||||||
console.log('Error', params);
|
|
||||||
}}
|
|
||||||
processRowUpdate={async (newRow, oldRow) => {
|
|
||||||
const data = dataFormatter.dataGridEditFormatter(newRow);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await handleTableSubmit(newRow.id, data);
|
|
||||||
return newRow;
|
|
||||||
} catch {
|
|
||||||
return oldRow;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
sortingMode={'server'}
|
|
||||||
checkboxSelection
|
|
||||||
onRowSelectionModelChange={(ids) => {
|
|
||||||
setSelectedRows(ids);
|
|
||||||
}}
|
|
||||||
onSortModelChange={(params) => {
|
|
||||||
params.length
|
|
||||||
? setSortModel(params)
|
|
||||||
: setSortModel([{ field: '', sort: 'desc' }]);
|
|
||||||
}}
|
|
||||||
rowCount={count}
|
|
||||||
pageSizeOptions={[10]}
|
|
||||||
paginationMode={'server'}
|
|
||||||
loading={loading}
|
|
||||||
onPaginationModelChange={(params) => {
|
|
||||||
onPageChange(params.page);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{filterItems && Array.isArray(filterItems) && filterItems.length ? (
|
|
||||||
<CardBox>
|
|
||||||
<Formik
|
|
||||||
initialValues={{
|
|
||||||
checkboxes: ['lorem'],
|
|
||||||
switches: ['lorem'],
|
|
||||||
radio: 'lorem',
|
|
||||||
}}
|
|
||||||
onSubmit={() => null}
|
|
||||||
>
|
|
||||||
<Form>
|
|
||||||
<>
|
|
||||||
{filterItems &&
|
|
||||||
filterItems.map((filterItem) => {
|
|
||||||
return (
|
|
||||||
<div key={filterItem.id} className='flex mb-4'>
|
|
||||||
<div className='flex flex-col w-full mr-3'>
|
|
||||||
<div className=' text-gray-500 font-bold'>
|
|
||||||
Filter
|
|
||||||
</div>
|
|
||||||
<Field
|
|
||||||
className={controlClasses}
|
|
||||||
name='selectedField'
|
|
||||||
id='selectedField'
|
|
||||||
component='select'
|
|
||||||
value={filterItem?.fields?.selectedField || ''}
|
|
||||||
onChange={handleChange(filterItem.id)}
|
|
||||||
>
|
|
||||||
{filters.map((selectOption) => (
|
|
||||||
<option
|
|
||||||
key={selectOption.title}
|
|
||||||
value={`${selectOption.title}`}
|
|
||||||
>
|
|
||||||
{selectOption.label}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</Field>
|
|
||||||
</div>
|
|
||||||
{filters.find(
|
|
||||||
(filter) =>
|
|
||||||
filter.title === filterItem?.fields?.selectedField,
|
|
||||||
)?.type === 'enum' ? (
|
|
||||||
<div className='flex flex-col w-full mr-3'>
|
|
||||||
<div className='text-gray-500 font-bold'>Value</div>
|
|
||||||
<Field
|
|
||||||
className={controlClasses}
|
|
||||||
name='filterValue'
|
|
||||||
id='filterValue'
|
|
||||||
component='select'
|
|
||||||
value={filterItem?.fields?.filterValue || ''}
|
|
||||||
onChange={handleChange(filterItem.id)}
|
|
||||||
>
|
|
||||||
<option value=''>Select Value</option>
|
|
||||||
{filters
|
|
||||||
.find(
|
|
||||||
(filter) =>
|
|
||||||
filter.title ===
|
|
||||||
filterItem?.fields?.selectedField,
|
|
||||||
)
|
|
||||||
?.options?.map((option) => (
|
|
||||||
<option key={option} value={option}>
|
|
||||||
{option}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</Field>
|
|
||||||
</div>
|
|
||||||
) : filters.find(
|
|
||||||
(filter) =>
|
|
||||||
filter.title ===
|
|
||||||
filterItem?.fields?.selectedField,
|
|
||||||
)?.number ? (
|
|
||||||
<div className='flex flex-row w-full mr-3'>
|
|
||||||
<div className='flex flex-col w-full mr-3'>
|
|
||||||
<div className=' text-gray-500 font-bold'>
|
|
||||||
From
|
|
||||||
</div>
|
|
||||||
<Field
|
|
||||||
className={controlClasses}
|
|
||||||
name='filterValueFrom'
|
|
||||||
placeholder='From'
|
|
||||||
id='filterValueFrom'
|
|
||||||
value={
|
|
||||||
filterItem?.fields?.filterValueFrom || ''
|
|
||||||
}
|
|
||||||
onChange={handleChange(filterItem.id)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className='flex flex-col w-full'>
|
|
||||||
<div className=' text-gray-500 font-bold'>
|
|
||||||
To
|
|
||||||
</div>
|
|
||||||
<Field
|
|
||||||
className={controlClasses}
|
|
||||||
name='filterValueTo'
|
|
||||||
placeholder='to'
|
|
||||||
id='filterValueTo'
|
|
||||||
value={filterItem?.fields?.filterValueTo || ''}
|
|
||||||
onChange={handleChange(filterItem.id)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
) : filters.find(
|
|
||||||
(filter) =>
|
|
||||||
filter.title ===
|
|
||||||
filterItem?.fields?.selectedField,
|
|
||||||
)?.date ? (
|
|
||||||
<div className='flex flex-row w-full mr-3'>
|
|
||||||
<div className='flex flex-col w-full mr-3'>
|
|
||||||
<div className=' text-gray-500 font-bold'>
|
|
||||||
From
|
|
||||||
</div>
|
|
||||||
<Field
|
|
||||||
className={controlClasses}
|
|
||||||
name='filterValueFrom'
|
|
||||||
placeholder='From'
|
|
||||||
id='filterValueFrom'
|
|
||||||
type='datetime-local'
|
|
||||||
value={
|
|
||||||
filterItem?.fields?.filterValueFrom || ''
|
|
||||||
}
|
|
||||||
onChange={handleChange(filterItem.id)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className='flex flex-col w-full'>
|
|
||||||
<div className=' text-gray-500 font-bold'>
|
|
||||||
To
|
|
||||||
</div>
|
|
||||||
<Field
|
|
||||||
className={controlClasses}
|
|
||||||
name='filterValueTo'
|
|
||||||
placeholder='to'
|
|
||||||
id='filterValueTo'
|
|
||||||
type='datetime-local'
|
|
||||||
value={filterItem?.fields?.filterValueTo || ''}
|
|
||||||
onChange={handleChange(filterItem.id)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className='flex flex-col w-full mr-3'>
|
|
||||||
<div className=' text-gray-500 font-bold'>
|
|
||||||
Contains
|
|
||||||
</div>
|
|
||||||
<Field
|
|
||||||
className={controlClasses}
|
|
||||||
name='filterValue'
|
|
||||||
placeholder='Contained'
|
|
||||||
id='filterValue'
|
|
||||||
value={filterItem?.fields?.filterValue || ''}
|
|
||||||
onChange={handleChange(filterItem.id)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div className='flex flex-col'>
|
|
||||||
<div className=' text-gray-500 font-bold'>
|
|
||||||
Action
|
|
||||||
</div>
|
|
||||||
<BaseButton
|
|
||||||
className='my-2'
|
|
||||||
type='reset'
|
|
||||||
color='danger'
|
|
||||||
label='Delete'
|
|
||||||
onClick={() => {
|
|
||||||
deleteFilter(filterItem.id);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
<div className='flex'>
|
|
||||||
<BaseButton
|
|
||||||
className='my-2 mr-3'
|
|
||||||
type='submit'
|
|
||||||
color='info'
|
|
||||||
label='Apply'
|
|
||||||
onClick={handleSubmit}
|
|
||||||
/>
|
|
||||||
<BaseButton
|
|
||||||
className='my-2'
|
|
||||||
type='reset'
|
|
||||||
color='info'
|
|
||||||
outline
|
|
||||||
label='Cancel'
|
|
||||||
onClick={handleReset}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
</Form>
|
|
||||||
</Formik>
|
|
||||||
</CardBox>
|
|
||||||
) : null}
|
|
||||||
<CardBoxModal
|
|
||||||
title='Please confirm'
|
|
||||||
buttonColor='info'
|
|
||||||
buttonLabel={loading ? 'Deleting...' : 'Confirm'}
|
|
||||||
isActive={isModalTrashActive}
|
|
||||||
onConfirm={handleDeleteAction}
|
|
||||||
onCancel={handleModalAction}
|
|
||||||
>
|
|
||||||
<p>Are you sure you want to delete this item?</p>
|
|
||||||
</CardBoxModal>
|
|
||||||
|
|
||||||
{dataGrid}
|
|
||||||
|
|
||||||
{selectedRows.length > 0 &&
|
|
||||||
createPortal(
|
|
||||||
<BaseButton
|
|
||||||
className='me-4'
|
|
||||||
color='danger'
|
|
||||||
label={`Delete ${selectedRows.length === 1 ? 'Row' : 'Rows'}`}
|
|
||||||
onClick={() => onDeleteRows(selectedRows)}
|
|
||||||
/>,
|
|
||||||
document.getElementById('delete-rows-button'),
|
|
||||||
)}
|
|
||||||
<ToastContainer />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default TableSampleScouting;
|
|
||||||
@ -1,160 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import BaseIcon from '../BaseIcon';
|
|
||||||
import { mdiEye, mdiTrashCan, mdiPencilOutline } from '@mdi/js';
|
|
||||||
import axios from 'axios';
|
|
||||||
import {
|
|
||||||
GridActionsCellItem,
|
|
||||||
GridRowParams,
|
|
||||||
GridValueGetterParams,
|
|
||||||
} from '@mui/x-data-grid';
|
|
||||||
import ImageField from '../ImageField';
|
|
||||||
import { saveFile } from '../../helpers/fileSaver';
|
|
||||||
import dataFormatter from '../../helpers/dataFormatter';
|
|
||||||
import DataGridMultiSelect from '../DataGridMultiSelect';
|
|
||||||
import ListActionsPopover from '../ListActionsPopover';
|
|
||||||
|
|
||||||
import { hasPermission } from '../../helpers/userPermissions';
|
|
||||||
|
|
||||||
type Params = (id: string) => void;
|
|
||||||
|
|
||||||
export const loadColumns = async (
|
|
||||||
onDelete: Params,
|
|
||||||
entityName: string,
|
|
||||||
|
|
||||||
user,
|
|
||||||
) => {
|
|
||||||
async function callOptionsApi(entityName: string) {
|
|
||||||
if (!hasPermission(user, 'READ_' + entityName.toUpperCase())) return [];
|
|
||||||
|
|
||||||
try {
|
|
||||||
const data = await axios(`/${entityName}/autocomplete?limit=100`);
|
|
||||||
return data.data;
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const hasUpdatePermission = hasPermission(user, 'UPDATE_SCOUTING');
|
|
||||||
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
field: 'team_number',
|
|
||||||
headerName: 'Team number',
|
|
||||||
flex: 1,
|
|
||||||
minWidth: 120,
|
|
||||||
filterable: false,
|
|
||||||
headerClassName: 'datagrid--header',
|
|
||||||
cellClassName: 'datagrid--cell',
|
|
||||||
|
|
||||||
editable: hasUpdatePermission,
|
|
||||||
|
|
||||||
type: 'number',
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
field: 'coral_l1',
|
|
||||||
headerName: 'Coral l1',
|
|
||||||
flex: 1,
|
|
||||||
minWidth: 120,
|
|
||||||
filterable: false,
|
|
||||||
headerClassName: 'datagrid--header',
|
|
||||||
cellClassName: 'datagrid--cell',
|
|
||||||
|
|
||||||
editable: hasUpdatePermission,
|
|
||||||
|
|
||||||
type: 'number',
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
field: 'coral_l2',
|
|
||||||
headerName: 'Coral l2',
|
|
||||||
flex: 1,
|
|
||||||
minWidth: 120,
|
|
||||||
filterable: false,
|
|
||||||
headerClassName: 'datagrid--header',
|
|
||||||
cellClassName: 'datagrid--cell',
|
|
||||||
|
|
||||||
editable: hasUpdatePermission,
|
|
||||||
|
|
||||||
type: 'number',
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
field: 'coral_l3',
|
|
||||||
headerName: 'Coral l3',
|
|
||||||
flex: 1,
|
|
||||||
minWidth: 120,
|
|
||||||
filterable: false,
|
|
||||||
headerClassName: 'datagrid--header',
|
|
||||||
cellClassName: 'datagrid--cell',
|
|
||||||
|
|
||||||
editable: hasUpdatePermission,
|
|
||||||
|
|
||||||
type: 'number',
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
field: 'coral_l4',
|
|
||||||
headerName: 'Coral l4',
|
|
||||||
flex: 1,
|
|
||||||
minWidth: 120,
|
|
||||||
filterable: false,
|
|
||||||
headerClassName: 'datagrid--header',
|
|
||||||
cellClassName: 'datagrid--cell',
|
|
||||||
|
|
||||||
editable: hasUpdatePermission,
|
|
||||||
|
|
||||||
type: 'number',
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
field: 'algae_processor',
|
|
||||||
headerName: 'Algae processor',
|
|
||||||
flex: 1,
|
|
||||||
minWidth: 120,
|
|
||||||
filterable: false,
|
|
||||||
headerClassName: 'datagrid--header',
|
|
||||||
cellClassName: 'datagrid--cell',
|
|
||||||
|
|
||||||
editable: hasUpdatePermission,
|
|
||||||
|
|
||||||
type: 'number',
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
field: 'algae_net',
|
|
||||||
headerName: 'Algae net',
|
|
||||||
flex: 1,
|
|
||||||
minWidth: 120,
|
|
||||||
filterable: false,
|
|
||||||
headerClassName: 'datagrid--header',
|
|
||||||
cellClassName: 'datagrid--cell',
|
|
||||||
|
|
||||||
editable: hasUpdatePermission,
|
|
||||||
|
|
||||||
type: 'number',
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
field: 'actions',
|
|
||||||
type: 'actions',
|
|
||||||
minWidth: 30,
|
|
||||||
headerClassName: 'datagrid--header',
|
|
||||||
cellClassName: 'datagrid--cell',
|
|
||||||
getActions: (params: GridRowParams) => {
|
|
||||||
return [
|
|
||||||
<div key={params?.row?.id}>
|
|
||||||
<ListActionsPopover
|
|
||||||
onDelete={onDelete}
|
|
||||||
itemId={params?.row?.id}
|
|
||||||
pathEdit={`/scouting/scouting-edit/?id=${params?.row?.id}`}
|
|
||||||
pathView={`/scouting/scouting-view/?id=${params?.row?.id}`}
|
|
||||||
hasUpdatePermission={hasUpdatePermission}
|
|
||||||
/>
|
|
||||||
</div>,
|
|
||||||
];
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
};
|
|
||||||
@ -17,9 +17,9 @@ export default function WebSiteFooter({ projectName }: WebSiteFooterProps) {
|
|||||||
const borders = useAppSelector((state) => state.style.borders);
|
const borders = useAppSelector((state) => state.style.borders);
|
||||||
const websiteHeder = useAppSelector((state) => state.style.websiteHeder);
|
const websiteHeder = useAppSelector((state) => state.style.websiteHeder);
|
||||||
|
|
||||||
const style = FooterStyle.WITH_PAGES;
|
const style = FooterStyle.WITH_PROJECT_NAME;
|
||||||
|
|
||||||
const design = FooterDesigns.DESIGN_DIVERSITY;
|
const design = FooterDesigns.DEFAULT_DESIGN;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@ -17,9 +17,9 @@ export default function WebSiteHeader({ projectName }: WebSiteHeaderProps) {
|
|||||||
const websiteHeder = useAppSelector((state) => state.style.websiteHeder);
|
const websiteHeder = useAppSelector((state) => state.style.websiteHeder);
|
||||||
const borders = useAppSelector((state) => state.style.borders);
|
const borders = useAppSelector((state) => state.style.borders);
|
||||||
|
|
||||||
const style = HeaderStyle.PAGES_RIGHT;
|
const style = HeaderStyle.PAGES_LEFT;
|
||||||
|
|
||||||
const design = HeaderDesigns.DESIGN_DIVERSITY;
|
const design = HeaderDesigns.DEFAULT_DESIGN;
|
||||||
return (
|
return (
|
||||||
<header id='websiteHeader' className='overflow-hidden'>
|
<header id='websiteHeader' className='overflow-hidden'>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@ -11,7 +11,7 @@ const HeroImageBg = ({
|
|||||||
<div
|
<div
|
||||||
className='relative w-full h-screen flex items-center justify-center text-center mb-24 bg-cover bg-center'
|
className='relative w-full h-screen flex items-center justify-center text-center mb-24 bg-cover bg-center'
|
||||||
style={{
|
style={{
|
||||||
backgroundImage: `url('https://static.wixstatic.com/media/42b9b7_04d3e636f03349f28be843bce8350e9f~mv2.png/v1/fill/w_1236,h_896,al_c,q_90,enc_avif,quality_auto/42b9b7_04d3e636f03349f28be843bce8350e9f~mv2.png')`,
|
backgroundImage: `url(${imageHero[0]?.src})`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className='absolute inset-0 bg-black opacity-50'></div>
|
<div className='absolute inset-0 bg-black opacity-50'></div>
|
||||||
|
|||||||
@ -1,16 +0,0 @@
|
|||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
interface ChatbotResponse {
|
|
||||||
reply: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a message to the in-house chatbot endpoint
|
|
||||||
* @param text user message
|
|
||||||
*/
|
|
||||||
const sendChatbotMessage = async (text: string): Promise<ChatbotResponse> => {
|
|
||||||
const response = await axios.post('/api/chatbot', { text });
|
|
||||||
return response.data;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default sendChatbotMessage;
|
|
||||||
@ -33,8 +33,6 @@ export async function getMultiplePexelsImages(
|
|||||||
}
|
}
|
||||||
localStorageLock = true;
|
localStorageLock = true;
|
||||||
|
|
||||||
// Force-clear old Pexels cache to load new Wix images
|
|
||||||
localStorage.removeItem('pexelsImagesCache');
|
|
||||||
const cachedImages =
|
const cachedImages =
|
||||||
JSON.parse(localStorage.getItem('pexelsImagesCache')) || {};
|
JSON.parse(localStorage.getItem('pexelsImagesCache')) || {};
|
||||||
|
|
||||||
|
|||||||
@ -76,25 +76,11 @@ const menuAside: MenuAsideItem[] = [
|
|||||||
icon: icon.mdiShieldAccountOutline ?? icon.mdiTable,
|
icon: icon.mdiShieldAccountOutline ?? icon.mdiTable,
|
||||||
permissions: 'READ_PERMISSIONS',
|
permissions: 'READ_PERMISSIONS',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
href: '/scouting',
|
|
||||||
label: 'Scouting',
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
icon: icon.mdiTable ?? icon.mdiTable,
|
|
||||||
permissions: 'READ_SCOUTING',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
href: '/profile',
|
href: '/profile',
|
||||||
label: 'Profile',
|
label: 'Profile',
|
||||||
icon: icon.mdiAccountCircle,
|
icon: icon.mdiAccountCircle,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
href: '/chatbot',
|
|
||||||
label: 'Chatbot',
|
|
||||||
icon: icon.mdiRobot,
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
href: '/home',
|
href: '/home',
|
||||||
|
|||||||
@ -1,73 +0,0 @@
|
|||||||
import React, { ReactElement, useState } from 'react';
|
|
||||||
import LayoutAuthenticated from '../layouts/Authenticated';
|
|
||||||
import SectionMain from '../components/SectionMain';
|
|
||||||
import SectionTitleLineWithButton from '../components/SectionTitleLineWithButton';
|
|
||||||
import CardBox from '../components/CardBox';
|
|
||||||
import sendChatbotMessage from '../helpers/chatbot';
|
|
||||||
import * as icon from '@mdi/js';
|
|
||||||
|
|
||||||
interface Message {
|
|
||||||
from: 'user' | 'bot';
|
|
||||||
text: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ChatbotPage: React.FC = () => {
|
|
||||||
const [input, setInput] = useState('');
|
|
||||||
const [messages, setMessages] = useState<Message[]>([]);
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
|
|
||||||
const handleSend = async () => {
|
|
||||||
if (!input.trim()) return;
|
|
||||||
const text = input.trim();
|
|
||||||
setMessages(prev => [...prev, { from: 'user', text }]);
|
|
||||||
setInput('');
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
const { reply } = await sendChatbotMessage(text);
|
|
||||||
setMessages(prev => [...prev, { from: 'bot', text: reply }]);
|
|
||||||
} catch (err) {
|
|
||||||
setMessages(prev => [...prev, { from: 'bot', text: 'Failed to get response. Please try again.' }]);
|
|
||||||
}
|
|
||||||
setLoading(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<SectionMain>
|
|
||||||
<SectionTitleLineWithButton icon={icon.mdiRobot} title="Chatbot" main>
|
|
||||||
Chat with team assistant
|
|
||||||
</SectionTitleLineWithButton>
|
|
||||||
<CardBox>
|
|
||||||
<div className="overflow-y-auto h-80 p-4 border rounded-md mb-4">
|
|
||||||
{messages.map((msg, idx) => (
|
|
||||||
<p key={idx} className={msg.from === 'user' ? 'text-right' : 'text-left'}>
|
|
||||||
<strong>{msg.from === 'user' ? 'You' : 'Bot'}:</strong> {msg.text}
|
|
||||||
</p>
|
|
||||||
))}
|
|
||||||
{loading && <p>Loading...</p>}
|
|
||||||
</div>
|
|
||||||
<div className="flex">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
className="flex-grow border p-2 rounded"
|
|
||||||
value={input}
|
|
||||||
onChange={e => setInput(e.target.value)}
|
|
||||||
placeholder="Type your message..."
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
className="ml-2 px-4 py-2 bg-purple-600 text-white rounded disabled:opacity-50"
|
|
||||||
onClick={handleSend}
|
|
||||||
disabled={loading}
|
|
||||||
>
|
|
||||||
Send
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</CardBox>
|
|
||||||
</SectionMain>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
ChatbotPage.getLayout = (page: ReactElement) => (
|
|
||||||
<LayoutAuthenticated>{page}</LayoutAuthenticated>
|
|
||||||
);
|
|
||||||
|
|
||||||
export default ChatbotPage;
|
|
||||||
@ -35,7 +35,6 @@ const Dashboard = () => {
|
|||||||
const [tasks, setTasks] = React.useState(loadingMessage);
|
const [tasks, setTasks] = React.useState(loadingMessage);
|
||||||
const [roles, setRoles] = React.useState(loadingMessage);
|
const [roles, setRoles] = React.useState(loadingMessage);
|
||||||
const [permissions, setPermissions] = React.useState(loadingMessage);
|
const [permissions, setPermissions] = React.useState(loadingMessage);
|
||||||
const [scouting, setScouting] = React.useState(loadingMessage);
|
|
||||||
|
|
||||||
const [widgetsRole, setWidgetsRole] = React.useState({
|
const [widgetsRole, setWidgetsRole] = React.useState({
|
||||||
role: { value: '', label: '' },
|
role: { value: '', label: '' },
|
||||||
@ -54,7 +53,6 @@ const Dashboard = () => {
|
|||||||
'tasks',
|
'tasks',
|
||||||
'roles',
|
'roles',
|
||||||
'permissions',
|
'permissions',
|
||||||
'scouting',
|
|
||||||
];
|
];
|
||||||
const fns = [
|
const fns = [
|
||||||
setUsers,
|
setUsers,
|
||||||
@ -64,7 +62,6 @@ const Dashboard = () => {
|
|||||||
setTasks,
|
setTasks,
|
||||||
setRoles,
|
setRoles,
|
||||||
setPermissions,
|
setPermissions,
|
||||||
setScouting,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const requests = entities.map((entity, index) => {
|
const requests = entities.map((entity, index) => {
|
||||||
@ -422,38 +419,6 @@ const Dashboard = () => {
|
|||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{hasPermission(currentUser, 'READ_SCOUTING') && (
|
|
||||||
<Link href={'/scouting/scouting-list'}>
|
|
||||||
<div
|
|
||||||
className={`${
|
|
||||||
corners !== 'rounded-full' ? corners : 'rounded-3xl'
|
|
||||||
} dark:bg-dark-900 ${cardsStyle} dark:border-dark-700 p-6`}
|
|
||||||
>
|
|
||||||
<div className='flex justify-between align-center'>
|
|
||||||
<div>
|
|
||||||
<div className='text-lg leading-tight text-gray-500 dark:text-gray-400'>
|
|
||||||
Scouting
|
|
||||||
</div>
|
|
||||||
<div className='text-3xl leading-tight font-semibold'>
|
|
||||||
{scouting}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<BaseIcon
|
|
||||||
className={`${iconsColor}`}
|
|
||||||
w='w-16'
|
|
||||||
h='h-16'
|
|
||||||
size={48}
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
path={icon.mdiTable || icon.mdiTable}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Link>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</SectionMain>
|
</SectionMain>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import FeaturesSection from '../components/WebPageComponents/FeaturesComponent';
|
|||||||
|
|
||||||
import GalleryPortfolioSection from '../components/WebPageComponents/GalleryPortfolioComponent';
|
import GalleryPortfolioSection from '../components/WebPageComponents/GalleryPortfolioComponent';
|
||||||
|
|
||||||
|
import { getMultiplePexelsImages } from '../helpers/pexels';
|
||||||
|
|
||||||
import AboutUsSection from '../components/WebPageComponents/AboutUsComponent';
|
import AboutUsSection from '../components/WebPageComponents/AboutUsComponent';
|
||||||
|
|
||||||
@ -78,13 +79,32 @@ export default function WebSite() {
|
|||||||
icon: 'mdiChartLine',
|
icon: 'mdiChartLine',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
// Use static Wix images for the gallery
|
|
||||||
const images = [
|
|
||||||
{ src: 'https://static.wixstatic.com/media/42b9b7_87daee7014234d78a8a0766bd8d906bd~mv2.jpeg/v1/crop/x_0,y_186,w_768,h_652/fill/w_768,h_652,al_c,q_85,enc_avif,quality_auto/WhatsApp%20Image%202023-11-07%20at%2019_31_00.jpeg' },
|
|
||||||
{ src: 'https://static.wixstatic.com/media/42b9b7_3e6e0cf2e71f4fca8c12705c35df1d61~mv2.jpg/v1/crop/x_59,y_0,w_905,h_768/fill/w_850,h_721,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/D29C232E-F61F-46B2-AF8C-1E29C87270C8_L0_001%20(1).jpg' },
|
|
||||||
{ src: 'https://static.wixstatic.com/media/42b9b7_b26e4585851c4e60a32d892baff6ca4e~mv2.png/v1/fill/w_529,h_678,al_c,lg_1,q_85,enc_avif,quality_auto/42b9b7_b26e4585851c4e60a32d892baff6ca4e~mv2.png' }
|
|
||||||
];
|
|
||||||
|
|
||||||
|
const [images, setImages] = useState([]);
|
||||||
|
const pexelsQueriesWebSite = [
|
||||||
|
'Team building the robot',
|
||||||
|
'Robotics competition excitement',
|
||||||
|
'Innovative robot design process',
|
||||||
|
'Team brainstorming session',
|
||||||
|
'Celebrating competition success',
|
||||||
|
];
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchImages = async () => {
|
||||||
|
try {
|
||||||
|
const images = await getMultiplePexelsImages(pexelsQueriesWebSite);
|
||||||
|
const formattedImages = (images || []).map((image) => ({
|
||||||
|
src: image?.src || undefined,
|
||||||
|
photographer: image?.photographer || undefined,
|
||||||
|
photographer_url: image?.photographer_url || undefined,
|
||||||
|
}));
|
||||||
|
setImages(formattedImages);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching images:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchImages();
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex flex-col min-h-screen'>
|
<div className='flex flex-col min-h-screen'>
|
||||||
@ -109,7 +129,7 @@ const images = [
|
|||||||
<FeaturesSection
|
<FeaturesSection
|
||||||
projectName={'Tucanus9050'}
|
projectName={'Tucanus9050'}
|
||||||
image={['Team collaborating on robot design']}
|
image={['Team collaborating on robot design']}
|
||||||
withBg={0}
|
withBg={1}
|
||||||
features={features_points}
|
features={features_points}
|
||||||
mainText={`Explore the Innovative Features of ${projectName}`}
|
mainText={`Explore the Innovative Features of ${projectName}`}
|
||||||
subTitle={`Discover the cutting-edge features that make the Tucanus FRC #9050 Robotics Team stand out in the FIRST Robotics Competition.`}
|
subTitle={`Discover the cutting-edge features that make the Tucanus FRC #9050 Robotics Team stand out in the FIRST Robotics Competition.`}
|
||||||
|
|||||||
@ -1,168 +0,0 @@
|
|||||||
import { mdiChartTimelineVariant, mdiUpload } from '@mdi/js';
|
|
||||||
import Head from 'next/head';
|
|
||||||
import React, { ReactElement, useEffect, useState } from 'react';
|
|
||||||
import DatePicker from 'react-datepicker';
|
|
||||||
import 'react-datepicker/dist/react-datepicker.css';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
|
|
||||||
import CardBox from '../../components/CardBox';
|
|
||||||
import LayoutAuthenticated from '../../layouts/Authenticated';
|
|
||||||
import SectionMain from '../../components/SectionMain';
|
|
||||||
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
|
||||||
import { getPageTitle } from '../../config';
|
|
||||||
|
|
||||||
import { Field, Form, Formik } from 'formik';
|
|
||||||
import FormField from '../../components/FormField';
|
|
||||||
import BaseDivider from '../../components/BaseDivider';
|
|
||||||
import BaseButtons from '../../components/BaseButtons';
|
|
||||||
import BaseButton from '../../components/BaseButton';
|
|
||||||
import FormCheckRadio from '../../components/FormCheckRadio';
|
|
||||||
import FormCheckRadioGroup from '../../components/FormCheckRadioGroup';
|
|
||||||
import FormFilePicker from '../../components/FormFilePicker';
|
|
||||||
import FormImagePicker from '../../components/FormImagePicker';
|
|
||||||
import { SelectField } from '../../components/SelectField';
|
|
||||||
import { SelectFieldMany } from '../../components/SelectFieldMany';
|
|
||||||
import { SwitchField } from '../../components/SwitchField';
|
|
||||||
import { RichTextField } from '../../components/RichTextField';
|
|
||||||
|
|
||||||
import { update, fetch } from '../../stores/scouting/scoutingSlice';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
|
||||||
import { useRouter } from 'next/router';
|
|
||||||
import { saveFile } from '../../helpers/fileSaver';
|
|
||||||
import dataFormatter from '../../helpers/dataFormatter';
|
|
||||||
import ImageField from '../../components/ImageField';
|
|
||||||
|
|
||||||
const EditScouting = () => {
|
|
||||||
const router = useRouter();
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
const initVals = {
|
|
||||||
team_number: '',
|
|
||||||
|
|
||||||
coral_l1: '',
|
|
||||||
|
|
||||||
coral_l2: '',
|
|
||||||
|
|
||||||
coral_l3: '',
|
|
||||||
|
|
||||||
coral_l4: '',
|
|
||||||
|
|
||||||
algae_processor: '',
|
|
||||||
|
|
||||||
algae_net: '',
|
|
||||||
};
|
|
||||||
const [initialValues, setInitialValues] = useState(initVals);
|
|
||||||
|
|
||||||
const { scouting } = useAppSelector((state) => state.scouting);
|
|
||||||
|
|
||||||
const { scoutingId } = router.query;
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
dispatch(fetch({ id: scoutingId }));
|
|
||||||
}, [scoutingId]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (typeof scouting === 'object') {
|
|
||||||
setInitialValues(scouting);
|
|
||||||
}
|
|
||||||
}, [scouting]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (typeof scouting === 'object') {
|
|
||||||
const newInitialVal = { ...initVals };
|
|
||||||
|
|
||||||
Object.keys(initVals).forEach((el) => (newInitialVal[el] = scouting[el]));
|
|
||||||
|
|
||||||
setInitialValues(newInitialVal);
|
|
||||||
}
|
|
||||||
}, [scouting]);
|
|
||||||
|
|
||||||
const handleSubmit = async (data) => {
|
|
||||||
await dispatch(update({ id: scoutingId, data }));
|
|
||||||
await router.push('/scouting/scouting-list');
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Head>
|
|
||||||
<title>{getPageTitle('Edit scouting')}</title>
|
|
||||||
</Head>
|
|
||||||
<SectionMain>
|
|
||||||
<SectionTitleLineWithButton
|
|
||||||
icon={mdiChartTimelineVariant}
|
|
||||||
title={'Edit scouting'}
|
|
||||||
main
|
|
||||||
>
|
|
||||||
{''}
|
|
||||||
</SectionTitleLineWithButton>
|
|
||||||
<CardBox>
|
|
||||||
<Formik
|
|
||||||
enableReinitialize
|
|
||||||
initialValues={initialValues}
|
|
||||||
onSubmit={(values) => handleSubmit(values)}
|
|
||||||
>
|
|
||||||
<Form>
|
|
||||||
<FormField label='Team number'>
|
|
||||||
<Field
|
|
||||||
type='number'
|
|
||||||
name='team_number'
|
|
||||||
placeholder='Team number'
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Coral l1'>
|
|
||||||
<Field type='number' name='coral_l1' placeholder='Coral l1' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Coral l2'>
|
|
||||||
<Field type='number' name='coral_l2' placeholder='Coral l2' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Coral l3'>
|
|
||||||
<Field type='number' name='coral_l3' placeholder='Coral l3' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Coral l4'>
|
|
||||||
<Field type='number' name='coral_l4' placeholder='Coral l4' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Algae processor'>
|
|
||||||
<Field
|
|
||||||
type='number'
|
|
||||||
name='algae_processor'
|
|
||||||
placeholder='Algae processor'
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Algae net'>
|
|
||||||
<Field type='number' name='algae_net' placeholder='Algae net' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<BaseDivider />
|
|
||||||
<BaseButtons>
|
|
||||||
<BaseButton type='submit' color='info' label='Submit' />
|
|
||||||
<BaseButton type='reset' color='info' outline label='Reset' />
|
|
||||||
<BaseButton
|
|
||||||
type='reset'
|
|
||||||
color='danger'
|
|
||||||
outline
|
|
||||||
label='Cancel'
|
|
||||||
onClick={() => router.push('/scouting/scouting-list')}
|
|
||||||
/>
|
|
||||||
</BaseButtons>
|
|
||||||
</Form>
|
|
||||||
</Formik>
|
|
||||||
</CardBox>
|
|
||||||
</SectionMain>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
EditScouting.getLayout = function getLayout(page: ReactElement) {
|
|
||||||
return (
|
|
||||||
<LayoutAuthenticated permission={'UPDATE_SCOUTING'}>
|
|
||||||
{page}
|
|
||||||
</LayoutAuthenticated>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default EditScouting;
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import Link from 'next/link';
|
|
||||||
import LayoutAuthenticated from '../../layouts/Authenticated';
|
|
||||||
import SectionMain from '../../components/SectionMain';
|
|
||||||
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
|
||||||
import CardBox from '../../components/CardBox';
|
|
||||||
|
|
||||||
const ScoutingIndex = () => (
|
|
||||||
<SectionMain>
|
|
||||||
<SectionTitleLineWithButton title="Scouting" main />
|
|
||||||
<CardBox>
|
|
||||||
<div className="flex flex-col space-y-4">
|
|
||||||
<Link href="/scouting/new" className="btn btn-primary">Scout a Team</Link>
|
|
||||||
<Link href="/scouting/scouting-list" className="btn btn-secondary">View Scouting Data</Link>
|
|
||||||
</div>
|
|
||||||
</CardBox>
|
|
||||||
</SectionMain>
|
|
||||||
);
|
|
||||||
|
|
||||||
ScoutingIndex.getLayout = page => <LayoutAuthenticated>{page}</LayoutAuthenticated>;
|
|
||||||
|
|
||||||
export default ScoutingIndex;
|
|
||||||
@ -1,166 +0,0 @@
|
|||||||
import { mdiChartTimelineVariant, mdiUpload } from '@mdi/js';
|
|
||||||
import Head from 'next/head';
|
|
||||||
import React, { ReactElement, useEffect, useState } from 'react';
|
|
||||||
import DatePicker from 'react-datepicker';
|
|
||||||
import 'react-datepicker/dist/react-datepicker.css';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
|
|
||||||
import CardBox from '../../components/CardBox';
|
|
||||||
import LayoutAuthenticated from '../../layouts/Authenticated';
|
|
||||||
import SectionMain from '../../components/SectionMain';
|
|
||||||
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
|
||||||
import { getPageTitle } from '../../config';
|
|
||||||
|
|
||||||
import { Field, Form, Formik } from 'formik';
|
|
||||||
import FormField from '../../components/FormField';
|
|
||||||
import BaseDivider from '../../components/BaseDivider';
|
|
||||||
import BaseButtons from '../../components/BaseButtons';
|
|
||||||
import BaseButton from '../../components/BaseButton';
|
|
||||||
import FormCheckRadio from '../../components/FormCheckRadio';
|
|
||||||
import FormCheckRadioGroup from '../../components/FormCheckRadioGroup';
|
|
||||||
import FormFilePicker from '../../components/FormFilePicker';
|
|
||||||
import FormImagePicker from '../../components/FormImagePicker';
|
|
||||||
import { SelectField } from '../../components/SelectField';
|
|
||||||
import { SelectFieldMany } from '../../components/SelectFieldMany';
|
|
||||||
import { SwitchField } from '../../components/SwitchField';
|
|
||||||
import { RichTextField } from '../../components/RichTextField';
|
|
||||||
|
|
||||||
import { update, fetch } from '../../stores/scouting/scoutingSlice';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
|
||||||
import { useRouter } from 'next/router';
|
|
||||||
import { saveFile } from '../../helpers/fileSaver';
|
|
||||||
import dataFormatter from '../../helpers/dataFormatter';
|
|
||||||
import ImageField from '../../components/ImageField';
|
|
||||||
|
|
||||||
const EditScoutingPage = () => {
|
|
||||||
const router = useRouter();
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
const initVals = {
|
|
||||||
team_number: '',
|
|
||||||
|
|
||||||
coral_l1: '',
|
|
||||||
|
|
||||||
coral_l2: '',
|
|
||||||
|
|
||||||
coral_l3: '',
|
|
||||||
|
|
||||||
coral_l4: '',
|
|
||||||
|
|
||||||
algae_processor: '',
|
|
||||||
|
|
||||||
algae_net: '',
|
|
||||||
};
|
|
||||||
const [initialValues, setInitialValues] = useState(initVals);
|
|
||||||
|
|
||||||
const { scouting } = useAppSelector((state) => state.scouting);
|
|
||||||
|
|
||||||
const { id } = router.query;
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
dispatch(fetch({ id: id }));
|
|
||||||
}, [id]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (typeof scouting === 'object') {
|
|
||||||
setInitialValues(scouting);
|
|
||||||
}
|
|
||||||
}, [scouting]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (typeof scouting === 'object') {
|
|
||||||
const newInitialVal = { ...initVals };
|
|
||||||
Object.keys(initVals).forEach((el) => (newInitialVal[el] = scouting[el]));
|
|
||||||
setInitialValues(newInitialVal);
|
|
||||||
}
|
|
||||||
}, [scouting]);
|
|
||||||
|
|
||||||
const handleSubmit = async (data) => {
|
|
||||||
await dispatch(update({ id: id, data }));
|
|
||||||
await router.push('/scouting/scouting-list');
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Head>
|
|
||||||
<title>{getPageTitle('Edit scouting')}</title>
|
|
||||||
</Head>
|
|
||||||
<SectionMain>
|
|
||||||
<SectionTitleLineWithButton
|
|
||||||
icon={mdiChartTimelineVariant}
|
|
||||||
title={'Edit scouting'}
|
|
||||||
main
|
|
||||||
>
|
|
||||||
{''}
|
|
||||||
</SectionTitleLineWithButton>
|
|
||||||
<CardBox>
|
|
||||||
<Formik
|
|
||||||
enableReinitialize
|
|
||||||
initialValues={initialValues}
|
|
||||||
onSubmit={(values) => handleSubmit(values)}
|
|
||||||
>
|
|
||||||
<Form>
|
|
||||||
<FormField label='Team number'>
|
|
||||||
<Field
|
|
||||||
type='number'
|
|
||||||
name='team_number'
|
|
||||||
placeholder='Team number'
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Coral l1'>
|
|
||||||
<Field type='number' name='coral_l1' placeholder='Coral l1' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Coral l2'>
|
|
||||||
<Field type='number' name='coral_l2' placeholder='Coral l2' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Coral l3'>
|
|
||||||
<Field type='number' name='coral_l3' placeholder='Coral l3' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Coral l4'>
|
|
||||||
<Field type='number' name='coral_l4' placeholder='Coral l4' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Algae processor'>
|
|
||||||
<Field
|
|
||||||
type='number'
|
|
||||||
name='algae_processor'
|
|
||||||
placeholder='Algae processor'
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Algae net'>
|
|
||||||
<Field type='number' name='algae_net' placeholder='Algae net' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<BaseDivider />
|
|
||||||
<BaseButtons>
|
|
||||||
<BaseButton type='submit' color='info' label='Submit' />
|
|
||||||
<BaseButton type='reset' color='info' outline label='Reset' />
|
|
||||||
<BaseButton
|
|
||||||
type='reset'
|
|
||||||
color='danger'
|
|
||||||
outline
|
|
||||||
label='Cancel'
|
|
||||||
onClick={() => router.push('/scouting/scouting-list')}
|
|
||||||
/>
|
|
||||||
</BaseButtons>
|
|
||||||
</Form>
|
|
||||||
</Formik>
|
|
||||||
</CardBox>
|
|
||||||
</SectionMain>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
EditScoutingPage.getLayout = function getLayout(page: ReactElement) {
|
|
||||||
return (
|
|
||||||
<LayoutAuthenticated permission={'UPDATE_SCOUTING'}>
|
|
||||||
{page}
|
|
||||||
</LayoutAuthenticated>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default EditScoutingPage;
|
|
||||||
@ -1,170 +0,0 @@
|
|||||||
import { mdiChartTimelineVariant } from '@mdi/js';
|
|
||||||
import Head from 'next/head';
|
|
||||||
import { uniqueId } from 'lodash';
|
|
||||||
import React, { ReactElement, useState } from 'react';
|
|
||||||
import CardBox from '../../components/CardBox';
|
|
||||||
import LayoutAuthenticated from '../../layouts/Authenticated';
|
|
||||||
import SectionMain from '../../components/SectionMain';
|
|
||||||
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
|
||||||
import { getPageTitle } from '../../config';
|
|
||||||
import TableScouting from '../../components/Scouting/TableScouting';
|
|
||||||
import BaseButton from '../../components/BaseButton';
|
|
||||||
import axios from 'axios';
|
|
||||||
import Link from 'next/link';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
|
||||||
import CardBoxModal from '../../components/CardBoxModal';
|
|
||||||
import DragDropFilePicker from '../../components/DragDropFilePicker';
|
|
||||||
import { setRefetch, uploadCsv } from '../../stores/scouting/scoutingSlice';
|
|
||||||
|
|
||||||
import { hasPermission } from '../../helpers/userPermissions';
|
|
||||||
|
|
||||||
const ScoutingTablesPage = () => {
|
|
||||||
const [filterItems, setFilterItems] = useState([]);
|
|
||||||
const [csvFile, setCsvFile] = useState<File | null>(null);
|
|
||||||
const [isModalActive, setIsModalActive] = useState(false);
|
|
||||||
const [showTableView, setShowTableView] = useState(false);
|
|
||||||
|
|
||||||
const { currentUser } = useAppSelector((state) => state.auth);
|
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
|
|
||||||
const [filters] = useState([
|
|
||||||
{ label: 'Team number', title: 'team_number', number: 'true' },
|
|
||||||
{ label: 'Coral l1', title: 'coral_l1', number: 'true' },
|
|
||||||
{ label: 'Coral l2', title: 'coral_l2', number: 'true' },
|
|
||||||
{ label: 'Coral l3', title: 'coral_l3', number: 'true' },
|
|
||||||
{ label: 'Coral l4', title: 'coral_l4', number: 'true' },
|
|
||||||
{ label: 'Algae processor', title: 'algae_processor', number: 'true' },
|
|
||||||
{ label: 'Algae net', title: 'algae_net', number: 'true' },
|
|
||||||
]);
|
|
||||||
|
|
||||||
const hasCreatePermission =
|
|
||||||
currentUser && hasPermission(currentUser, 'CREATE_SCOUTING');
|
|
||||||
|
|
||||||
const addFilter = () => {
|
|
||||||
const newItem = {
|
|
||||||
id: uniqueId(),
|
|
||||||
fields: {
|
|
||||||
filterValue: '',
|
|
||||||
filterValueFrom: '',
|
|
||||||
filterValueTo: '',
|
|
||||||
selectedField: '',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
newItem.fields.selectedField = filters[0].title;
|
|
||||||
setFilterItems([...filterItems, newItem]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getScoutingCSV = async () => {
|
|
||||||
const response = await axios({
|
|
||||||
url: '/scouting?filetype=csv',
|
|
||||||
method: 'GET',
|
|
||||||
responseType: 'blob',
|
|
||||||
});
|
|
||||||
const type = response.headers['content-type'];
|
|
||||||
const blob = new Blob([response.data], { type: type });
|
|
||||||
const link = document.createElement('a');
|
|
||||||
link.href = window.URL.createObjectURL(blob);
|
|
||||||
link.download = 'scoutingCSV.csv';
|
|
||||||
link.click();
|
|
||||||
};
|
|
||||||
|
|
||||||
const onModalConfirm = async () => {
|
|
||||||
if (!csvFile) return;
|
|
||||||
await dispatch(uploadCsv(csvFile));
|
|
||||||
dispatch(setRefetch(true));
|
|
||||||
setCsvFile(null);
|
|
||||||
setIsModalActive(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onModalCancel = () => {
|
|
||||||
setCsvFile(null);
|
|
||||||
setIsModalActive(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Head>
|
|
||||||
<title>{getPageTitle('Scouting')}</title>
|
|
||||||
</Head>
|
|
||||||
<SectionMain>
|
|
||||||
<SectionTitleLineWithButton
|
|
||||||
icon={mdiChartTimelineVariant}
|
|
||||||
title='Scouting'
|
|
||||||
main
|
|
||||||
>
|
|
||||||
{''}
|
|
||||||
</SectionTitleLineWithButton>
|
|
||||||
<CardBox className='mb-6' cardBoxClassName='flex flex-wrap'>
|
|
||||||
{hasCreatePermission && (
|
|
||||||
<BaseButton
|
|
||||||
className={'mr-3'}
|
|
||||||
href={'/scouting/scouting-new'}
|
|
||||||
color='info'
|
|
||||||
label='New Item'
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<BaseButton
|
|
||||||
className={'mr-3'}
|
|
||||||
color='info'
|
|
||||||
label='Filter'
|
|
||||||
onClick={addFilter}
|
|
||||||
/>
|
|
||||||
<BaseButton
|
|
||||||
className={'mr-3'}
|
|
||||||
color='info'
|
|
||||||
label='Download CSV'
|
|
||||||
onClick={getScoutingCSV}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{hasCreatePermission && (
|
|
||||||
<BaseButton
|
|
||||||
color='info'
|
|
||||||
label='Upload CSV'
|
|
||||||
onClick={() => setIsModalActive(true)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className='md:inline-flex items-center ms-auto'>
|
|
||||||
<div id='delete-rows-button'></div>
|
|
||||||
</div>
|
|
||||||
</CardBox>
|
|
||||||
|
|
||||||
<CardBox className='mb-6' hasTable>
|
|
||||||
<TableScouting
|
|
||||||
filterItems={filterItems}
|
|
||||||
setFilterItems={setFilterItems}
|
|
||||||
filters={filters}
|
|
||||||
showGrid={false}
|
|
||||||
/>
|
|
||||||
</CardBox>
|
|
||||||
</SectionMain>
|
|
||||||
<CardBoxModal
|
|
||||||
title='Upload CSV'
|
|
||||||
buttonColor='info'
|
|
||||||
buttonLabel={'Confirm'}
|
|
||||||
// buttonLabel={false ? 'Deleting...' : 'Confirm'}
|
|
||||||
isActive={isModalActive}
|
|
||||||
onConfirm={onModalConfirm}
|
|
||||||
onCancel={onModalCancel}
|
|
||||||
>
|
|
||||||
<DragDropFilePicker
|
|
||||||
file={csvFile}
|
|
||||||
setFile={setCsvFile}
|
|
||||||
formats={'.csv'}
|
|
||||||
/>
|
|
||||||
</CardBoxModal>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
ScoutingTablesPage.getLayout = function getLayout(page: ReactElement) {
|
|
||||||
return (
|
|
||||||
<LayoutAuthenticated permission={'READ_SCOUTING'}>
|
|
||||||
{page}
|
|
||||||
</LayoutAuthenticated>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ScoutingTablesPage;
|
|
||||||
@ -1,142 +0,0 @@
|
|||||||
import {
|
|
||||||
mdiAccount,
|
|
||||||
mdiChartTimelineVariant,
|
|
||||||
mdiMail,
|
|
||||||
mdiUpload,
|
|
||||||
} from '@mdi/js';
|
|
||||||
import Head from 'next/head';
|
|
||||||
import React, { ReactElement } from 'react';
|
|
||||||
import CardBox from '../../components/CardBox';
|
|
||||||
import LayoutAuthenticated from '../../layouts/Authenticated';
|
|
||||||
import SectionMain from '../../components/SectionMain';
|
|
||||||
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
|
||||||
import { getPageTitle } from '../../config';
|
|
||||||
|
|
||||||
import { Field, Form, Formik } from 'formik';
|
|
||||||
import FormField from '../../components/FormField';
|
|
||||||
import BaseDivider from '../../components/BaseDivider';
|
|
||||||
import BaseButtons from '../../components/BaseButtons';
|
|
||||||
import BaseButton from '../../components/BaseButton';
|
|
||||||
import FormCheckRadio from '../../components/FormCheckRadio';
|
|
||||||
import FormCheckRadioGroup from '../../components/FormCheckRadioGroup';
|
|
||||||
import FormFilePicker from '../../components/FormFilePicker';
|
|
||||||
import FormImagePicker from '../../components/FormImagePicker';
|
|
||||||
import { SwitchField } from '../../components/SwitchField';
|
|
||||||
|
|
||||||
import { SelectField } from '../../components/SelectField';
|
|
||||||
import { SelectFieldMany } from '../../components/SelectFieldMany';
|
|
||||||
import { RichTextField } from '../../components/RichTextField';
|
|
||||||
|
|
||||||
import { create } from '../../stores/scouting/scoutingSlice';
|
|
||||||
import { useAppDispatch } from '../../stores/hooks';
|
|
||||||
import { useRouter } from 'next/router';
|
|
||||||
import moment from 'moment';
|
|
||||||
|
|
||||||
const initialValues = {
|
|
||||||
team_number: '',
|
|
||||||
|
|
||||||
coral_l1: '',
|
|
||||||
|
|
||||||
coral_l2: '',
|
|
||||||
|
|
||||||
coral_l3: '',
|
|
||||||
|
|
||||||
coral_l4: '',
|
|
||||||
|
|
||||||
algae_processor: '',
|
|
||||||
|
|
||||||
algae_net: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
const ScoutingNew = () => {
|
|
||||||
const router = useRouter();
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
|
|
||||||
const handleSubmit = async (data) => {
|
|
||||||
await dispatch(create(data));
|
|
||||||
await router.push('/scouting/scouting-list');
|
|
||||||
};
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Head>
|
|
||||||
<title>{getPageTitle('New Item')}</title>
|
|
||||||
</Head>
|
|
||||||
<SectionMain>
|
|
||||||
<SectionTitleLineWithButton
|
|
||||||
icon={mdiChartTimelineVariant}
|
|
||||||
title='New Item'
|
|
||||||
main
|
|
||||||
>
|
|
||||||
{''}
|
|
||||||
</SectionTitleLineWithButton>
|
|
||||||
<CardBox>
|
|
||||||
<Formik
|
|
||||||
initialValues={initialValues}
|
|
||||||
onSubmit={(values) => handleSubmit(values)}
|
|
||||||
>
|
|
||||||
<Form>
|
|
||||||
<FormField label='Team number'>
|
|
||||||
<Field
|
|
||||||
type='number'
|
|
||||||
name='team_number'
|
|
||||||
placeholder='Team number'
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Coral l1'>
|
|
||||||
<Field type='number' name='coral_l1' placeholder='Coral l1' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Coral l2'>
|
|
||||||
<Field type='number' name='coral_l2' placeholder='Coral l2' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Coral l3'>
|
|
||||||
<Field type='number' name='coral_l3' placeholder='Coral l3' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Coral l4'>
|
|
||||||
<Field type='number' name='coral_l4' placeholder='Coral l4' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Algae processor'>
|
|
||||||
<Field
|
|
||||||
type='number'
|
|
||||||
name='algae_processor'
|
|
||||||
placeholder='Algae processor'
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label='Algae net'>
|
|
||||||
<Field type='number' name='algae_net' placeholder='Algae net' />
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<BaseDivider />
|
|
||||||
<BaseButtons>
|
|
||||||
<BaseButton type='submit' color='info' label='Submit' />
|
|
||||||
<BaseButton type='reset' color='info' outline label='Reset' />
|
|
||||||
<BaseButton
|
|
||||||
type='reset'
|
|
||||||
color='danger'
|
|
||||||
outline
|
|
||||||
label='Cancel'
|
|
||||||
onClick={() => router.push('/scouting/scouting-list')}
|
|
||||||
/>
|
|
||||||
</BaseButtons>
|
|
||||||
</Form>
|
|
||||||
</Formik>
|
|
||||||
</CardBox>
|
|
||||||
</SectionMain>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
ScoutingNew.getLayout = function getLayout(page: ReactElement) {
|
|
||||||
return (
|
|
||||||
<LayoutAuthenticated permission={'CREATE_SCOUTING'}>
|
|
||||||
{page}
|
|
||||||
</LayoutAuthenticated>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ScoutingNew;
|
|
||||||
@ -1,169 +0,0 @@
|
|||||||
import { mdiChartTimelineVariant } from '@mdi/js';
|
|
||||||
import Head from 'next/head';
|
|
||||||
import { uniqueId } from 'lodash';
|
|
||||||
import React, { ReactElement, useState } from 'react';
|
|
||||||
import CardBox from '../../components/CardBox';
|
|
||||||
import LayoutAuthenticated from '../../layouts/Authenticated';
|
|
||||||
import SectionMain from '../../components/SectionMain';
|
|
||||||
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
|
||||||
import { getPageTitle } from '../../config';
|
|
||||||
import TableScouting from '../../components/Scouting/TableScouting';
|
|
||||||
import BaseButton from '../../components/BaseButton';
|
|
||||||
import axios from 'axios';
|
|
||||||
import Link from 'next/link';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
|
||||||
import CardBoxModal from '../../components/CardBoxModal';
|
|
||||||
import DragDropFilePicker from '../../components/DragDropFilePicker';
|
|
||||||
import { setRefetch, uploadCsv } from '../../stores/scouting/scoutingSlice';
|
|
||||||
|
|
||||||
import { hasPermission } from '../../helpers/userPermissions';
|
|
||||||
|
|
||||||
const ScoutingTablesPage = () => {
|
|
||||||
const [filterItems, setFilterItems] = useState([]);
|
|
||||||
const [csvFile, setCsvFile] = useState<File | null>(null);
|
|
||||||
const [isModalActive, setIsModalActive] = useState(false);
|
|
||||||
const [showTableView, setShowTableView] = useState(false);
|
|
||||||
|
|
||||||
const { currentUser } = useAppSelector((state) => state.auth);
|
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
|
|
||||||
const [filters] = useState([
|
|
||||||
{ label: 'Team number', title: 'team_number', number: 'true' },
|
|
||||||
{ label: 'Coral l1', title: 'coral_l1', number: 'true' },
|
|
||||||
{ label: 'Coral l2', title: 'coral_l2', number: 'true' },
|
|
||||||
{ label: 'Coral l3', title: 'coral_l3', number: 'true' },
|
|
||||||
{ label: 'Coral l4', title: 'coral_l4', number: 'true' },
|
|
||||||
{ label: 'Algae processor', title: 'algae_processor', number: 'true' },
|
|
||||||
{ label: 'Algae net', title: 'algae_net', number: 'true' },
|
|
||||||
]);
|
|
||||||
|
|
||||||
const hasCreatePermission =
|
|
||||||
currentUser && hasPermission(currentUser, 'CREATE_SCOUTING');
|
|
||||||
|
|
||||||
const addFilter = () => {
|
|
||||||
const newItem = {
|
|
||||||
id: uniqueId(),
|
|
||||||
fields: {
|
|
||||||
filterValue: '',
|
|
||||||
filterValueFrom: '',
|
|
||||||
filterValueTo: '',
|
|
||||||
selectedField: '',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
newItem.fields.selectedField = filters[0].title;
|
|
||||||
setFilterItems([...filterItems, newItem]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getScoutingCSV = async () => {
|
|
||||||
const response = await axios({
|
|
||||||
url: '/scouting?filetype=csv',
|
|
||||||
method: 'GET',
|
|
||||||
responseType: 'blob',
|
|
||||||
});
|
|
||||||
const type = response.headers['content-type'];
|
|
||||||
const blob = new Blob([response.data], { type: type });
|
|
||||||
const link = document.createElement('a');
|
|
||||||
link.href = window.URL.createObjectURL(blob);
|
|
||||||
link.download = 'scoutingCSV.csv';
|
|
||||||
link.click();
|
|
||||||
};
|
|
||||||
|
|
||||||
const onModalConfirm = async () => {
|
|
||||||
if (!csvFile) return;
|
|
||||||
await dispatch(uploadCsv(csvFile));
|
|
||||||
dispatch(setRefetch(true));
|
|
||||||
setCsvFile(null);
|
|
||||||
setIsModalActive(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onModalCancel = () => {
|
|
||||||
setCsvFile(null);
|
|
||||||
setIsModalActive(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Head>
|
|
||||||
<title>{getPageTitle('Scouting')}</title>
|
|
||||||
</Head>
|
|
||||||
<SectionMain>
|
|
||||||
<SectionTitleLineWithButton
|
|
||||||
icon={mdiChartTimelineVariant}
|
|
||||||
title='Scouting'
|
|
||||||
main
|
|
||||||
>
|
|
||||||
{''}
|
|
||||||
</SectionTitleLineWithButton>
|
|
||||||
<CardBox className='mb-6' cardBoxClassName='flex flex-wrap'>
|
|
||||||
{hasCreatePermission && (
|
|
||||||
<BaseButton
|
|
||||||
className={'mr-3'}
|
|
||||||
href={'/scouting/scouting-new'}
|
|
||||||
color='info'
|
|
||||||
label='New Item'
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<BaseButton
|
|
||||||
className={'mr-3'}
|
|
||||||
color='info'
|
|
||||||
label='Filter'
|
|
||||||
onClick={addFilter}
|
|
||||||
/>
|
|
||||||
<BaseButton
|
|
||||||
className={'mr-3'}
|
|
||||||
color='info'
|
|
||||||
label='Download CSV'
|
|
||||||
onClick={getScoutingCSV}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{hasCreatePermission && (
|
|
||||||
<BaseButton
|
|
||||||
color='info'
|
|
||||||
label='Upload CSV'
|
|
||||||
onClick={() => setIsModalActive(true)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className='md:inline-flex items-center ms-auto'>
|
|
||||||
<div id='delete-rows-button'></div>
|
|
||||||
</div>
|
|
||||||
</CardBox>
|
|
||||||
<CardBox className='mb-6' hasTable>
|
|
||||||
<TableScouting
|
|
||||||
filterItems={filterItems}
|
|
||||||
setFilterItems={setFilterItems}
|
|
||||||
filters={filters}
|
|
||||||
showGrid={true}
|
|
||||||
/>
|
|
||||||
</CardBox>
|
|
||||||
</SectionMain>
|
|
||||||
<CardBoxModal
|
|
||||||
title='Upload CSV'
|
|
||||||
buttonColor='info'
|
|
||||||
buttonLabel={'Confirm'}
|
|
||||||
// buttonLabel={false ? 'Deleting...' : 'Confirm'}
|
|
||||||
isActive={isModalActive}
|
|
||||||
onConfirm={onModalConfirm}
|
|
||||||
onCancel={onModalCancel}
|
|
||||||
>
|
|
||||||
<DragDropFilePicker
|
|
||||||
file={csvFile}
|
|
||||||
setFile={setCsvFile}
|
|
||||||
formats={'.csv'}
|
|
||||||
/>
|
|
||||||
</CardBoxModal>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
ScoutingTablesPage.getLayout = function getLayout(page: ReactElement) {
|
|
||||||
return (
|
|
||||||
<LayoutAuthenticated permission={'READ_SCOUTING'}>
|
|
||||||
{page}
|
|
||||||
</LayoutAuthenticated>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ScoutingTablesPage;
|
|
||||||
@ -1,113 +0,0 @@
|
|||||||
import React, { ReactElement, useEffect } from 'react';
|
|
||||||
import Head from 'next/head';
|
|
||||||
import DatePicker from 'react-datepicker';
|
|
||||||
import 'react-datepicker/dist/react-datepicker.css';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../stores/hooks';
|
|
||||||
import { useRouter } from 'next/router';
|
|
||||||
import { fetch } from '../../stores/scouting/scoutingSlice';
|
|
||||||
import { saveFile } from '../../helpers/fileSaver';
|
|
||||||
import dataFormatter from '../../helpers/dataFormatter';
|
|
||||||
import ImageField from '../../components/ImageField';
|
|
||||||
import LayoutAuthenticated from '../../layouts/Authenticated';
|
|
||||||
import { getPageTitle } from '../../config';
|
|
||||||
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton';
|
|
||||||
import SectionMain from '../../components/SectionMain';
|
|
||||||
import CardBox from '../../components/CardBox';
|
|
||||||
import BaseButton from '../../components/BaseButton';
|
|
||||||
import BaseDivider from '../../components/BaseDivider';
|
|
||||||
import { mdiChartTimelineVariant } from '@mdi/js';
|
|
||||||
import { SwitchField } from '../../components/SwitchField';
|
|
||||||
import FormField from '../../components/FormField';
|
|
||||||
|
|
||||||
const ScoutingView = () => {
|
|
||||||
const router = useRouter();
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
const { scouting } = useAppSelector((state) => state.scouting);
|
|
||||||
|
|
||||||
const { id } = router.query;
|
|
||||||
|
|
||||||
function removeLastCharacter(str) {
|
|
||||||
console.log(str, `str`);
|
|
||||||
return str.slice(0, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
dispatch(fetch({ id }));
|
|
||||||
}, [dispatch, id]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Head>
|
|
||||||
<title>{getPageTitle('View scouting')}</title>
|
|
||||||
</Head>
|
|
||||||
<SectionMain>
|
|
||||||
<SectionTitleLineWithButton
|
|
||||||
icon={mdiChartTimelineVariant}
|
|
||||||
title={removeLastCharacter('View scouting')}
|
|
||||||
main
|
|
||||||
>
|
|
||||||
<BaseButton
|
|
||||||
color='info'
|
|
||||||
label='Edit'
|
|
||||||
href={`/scouting/scouting-edit/?id=${id}`}
|
|
||||||
/>
|
|
||||||
</SectionTitleLineWithButton>
|
|
||||||
<CardBox>
|
|
||||||
<div className={'mb-4'}>
|
|
||||||
<p className={'block font-bold mb-2'}>Team number</p>
|
|
||||||
<p>{scouting?.team_number || 'No data'}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={'mb-4'}>
|
|
||||||
<p className={'block font-bold mb-2'}>Coral l1</p>
|
|
||||||
<p>{scouting?.coral_l1 || 'No data'}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={'mb-4'}>
|
|
||||||
<p className={'block font-bold mb-2'}>Coral l2</p>
|
|
||||||
<p>{scouting?.coral_l2 || 'No data'}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={'mb-4'}>
|
|
||||||
<p className={'block font-bold mb-2'}>Coral l3</p>
|
|
||||||
<p>{scouting?.coral_l3 || 'No data'}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={'mb-4'}>
|
|
||||||
<p className={'block font-bold mb-2'}>Coral l4</p>
|
|
||||||
<p>{scouting?.coral_l4 || 'No data'}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={'mb-4'}>
|
|
||||||
<p className={'block font-bold mb-2'}>Algae processor</p>
|
|
||||||
<p>{scouting?.algae_processor || 'No data'}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={'mb-4'}>
|
|
||||||
<p className={'block font-bold mb-2'}>Algae net</p>
|
|
||||||
<p>{scouting?.algae_net || 'No data'}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<BaseDivider />
|
|
||||||
|
|
||||||
<BaseButton
|
|
||||||
color='info'
|
|
||||||
label='Back'
|
|
||||||
onClick={() => router.push('/scouting/scouting-list')}
|
|
||||||
/>
|
|
||||||
</CardBox>
|
|
||||||
</SectionMain>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
ScoutingView.getLayout = function getLayout(page: ReactElement) {
|
|
||||||
return (
|
|
||||||
<LayoutAuthenticated permission={'READ_SCOUTING'}>
|
|
||||||
{page}
|
|
||||||
</LayoutAuthenticated>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ScoutingView;
|
|
||||||
@ -20,6 +20,7 @@ import FeaturesSection from '../../components/WebPageComponents/FeaturesComponen
|
|||||||
|
|
||||||
import GalleryPortfolioSection from '../../components/WebPageComponents/GalleryPortfolioComponent';
|
import GalleryPortfolioSection from '../../components/WebPageComponents/GalleryPortfolioComponent';
|
||||||
|
|
||||||
|
import { getMultiplePexelsImages } from '../../helpers/pexels';
|
||||||
|
|
||||||
import AboutUsSection from '../../components/WebPageComponents/AboutUsComponent';
|
import AboutUsSection from '../../components/WebPageComponents/AboutUsComponent';
|
||||||
|
|
||||||
@ -58,11 +59,31 @@ export default function WebSite() {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const images = [
|
const [images, setImages] = useState([]);
|
||||||
{ src: 'https://static.wixstatic.com/media/42b9b7_87daee7014234d78a8a0766bd8d906bd~mv2.jpeg/v1/crop/x_0,y_186,w_768,h_652/fill/w_768,h_652,al_c,q_85,enc_avif,quality_auto/WhatsApp%20Image%202023-11-07%20at%2019_31_00.jpeg' },
|
const pexelsQueriesWebSite = [
|
||||||
{ src: 'https://static.wixstatic.com/media/42b9b7_3e6e0cf2e71f4fca8c12705c35df1d61~mv2.jpg/v1/crop/x_59,y_0,w_905,h_768/fill/w_850,h_721,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/D29C232E-F61F-46B2-AF8C-1E29C87270C8_L0_001%20(1).jpg' },
|
'Team building the robot',
|
||||||
{ src: 'https://static.wixstatic.com/media/42b9b7_b26e4585851c4e60a32d892baff6ca4e~mv2.png/v1/fill/w_529,h_678,al_c,lg_1,q_85,enc_avif,quality_auto/42b9b7_b26e4585851c4e60a32d892baff6ca4e~mv2.png' }
|
'Robotics competition excitement',
|
||||||
|
'Innovative robot design process',
|
||||||
|
'Team brainstorming session',
|
||||||
|
'Celebrating competition success',
|
||||||
];
|
];
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchImages = async () => {
|
||||||
|
try {
|
||||||
|
const images = await getMultiplePexelsImages(pexelsQueriesWebSite);
|
||||||
|
const formattedImages = (images || []).map((image) => ({
|
||||||
|
src: image?.src || undefined,
|
||||||
|
photographer: image?.photographer || undefined,
|
||||||
|
photographer_url: image?.photographer_url || undefined,
|
||||||
|
}));
|
||||||
|
setImages(formattedImages);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching images:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchImages();
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex flex-col min-h-screen'>
|
<div className='flex flex-col min-h-screen'>
|
||||||
|
|||||||
@ -36,7 +36,7 @@ export const aiPrompt = createAsyncThunk(
|
|||||||
'openai/aiPrompt',
|
'openai/aiPrompt',
|
||||||
async (data: any, { rejectWithValue }) => {
|
async (data: any, { rejectWithValue }) => {
|
||||||
try {
|
try {
|
||||||
return await axios.post('/api/openai/create_widget', data);
|
return await axios.post('/openai/create_widget', data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!error.response) {
|
if (!error.response) {
|
||||||
throw error;
|
throw error;
|
||||||
@ -48,14 +48,9 @@ export const aiPrompt = createAsyncThunk(
|
|||||||
|
|
||||||
export const askGpt = createAsyncThunk(
|
export const askGpt = createAsyncThunk(
|
||||||
'openai/askGpt',
|
'openai/askGpt',
|
||||||
async (prompt: string, { rejectWithValue, getState }) => {
|
async (prompt: string, { rejectWithValue }) => {
|
||||||
try {
|
try {
|
||||||
const token = (getState() as any).auth.token;
|
const response = await axios.post('/openai/ask-gpt', { prompt });
|
||||||
const response = await axios.post(
|
|
||||||
'/api/openai/ask-gpt',
|
|
||||||
{ prompt },
|
|
||||||
{ headers: { Authorization: `Bearer ${token}` } }
|
|
||||||
);
|
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!error.response) {
|
if (!error.response) {
|
||||||
|
|||||||
@ -1,236 +0,0 @@
|
|||||||
import { createSlice, createAsyncThunk, PayloadAction } from '@reduxjs/toolkit';
|
|
||||||
import axios from 'axios';
|
|
||||||
import {
|
|
||||||
fulfilledNotify,
|
|
||||||
rejectNotify,
|
|
||||||
resetNotify,
|
|
||||||
} from '../../helpers/notifyStateHandler';
|
|
||||||
|
|
||||||
interface MainState {
|
|
||||||
scouting: any;
|
|
||||||
loading: boolean;
|
|
||||||
count: number;
|
|
||||||
refetch: boolean;
|
|
||||||
rolesWidgets: any[];
|
|
||||||
notify: {
|
|
||||||
showNotification: boolean;
|
|
||||||
textNotification: string;
|
|
||||||
typeNotification: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const initialState: MainState = {
|
|
||||||
scouting: [],
|
|
||||||
loading: false,
|
|
||||||
count: 0,
|
|
||||||
refetch: false,
|
|
||||||
rolesWidgets: [],
|
|
||||||
notify: {
|
|
||||||
showNotification: false,
|
|
||||||
textNotification: '',
|
|
||||||
typeNotification: 'warn',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const fetch = createAsyncThunk('scouting/fetch', async (data: any) => {
|
|
||||||
const { id, query } = data;
|
|
||||||
const result = await axios.get(`/api/scouting${query || (id ? `/${id}` : '')}`);
|
|
||||||
return id
|
|
||||||
? result.data
|
|
||||||
: { rows: result.data.rows, count: result.data.count };
|
|
||||||
});
|
|
||||||
|
|
||||||
export const deleteItemsByIds = createAsyncThunk(
|
|
||||||
'scouting/deleteByIds',
|
|
||||||
async (data: any, { rejectWithValue }) => {
|
|
||||||
try {
|
|
||||||
await axios.post('/api/scouting/deleteByIds', { data });
|
|
||||||
} catch (error) {
|
|
||||||
if (!error.response) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export const deleteItem = createAsyncThunk(
|
|
||||||
'scouting/deleteScouting',
|
|
||||||
async (id: string, { rejectWithValue }) => {
|
|
||||||
try {
|
|
||||||
await axios.delete(`/api/scouting/${id}`);
|
|
||||||
} catch (error) {
|
|
||||||
if (!error.response) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export const create = createAsyncThunk(
|
|
||||||
'scouting/createScouting',
|
|
||||||
async (data: any, { rejectWithValue }) => {
|
|
||||||
try {
|
|
||||||
const result = await axios.post('/api/scouting', { data }, { withCredentials: true });
|
|
||||||
return result.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (!error.response) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export const uploadCsv = createAsyncThunk(
|
|
||||||
'scouting/uploadCsv',
|
|
||||||
async (file: File, { rejectWithValue }) => {
|
|
||||||
try {
|
|
||||||
const data = new FormData();
|
|
||||||
data.append('file', file);
|
|
||||||
data.append('filename', file.name);
|
|
||||||
|
|
||||||
const result = await axios.post('scouting/bulk-import', data, {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'multipart/form-data',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return result.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (!error.response) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export const update = createAsyncThunk(
|
|
||||||
'scouting/updateScouting',
|
|
||||||
async (payload: any, { rejectWithValue }) => {
|
|
||||||
try {
|
|
||||||
const result = await axios.put(`scouting/${payload.id}`, {
|
|
||||||
id: payload.id,
|
|
||||||
data: payload.data,
|
|
||||||
});
|
|
||||||
return result.data;
|
|
||||||
} catch (error) {
|
|
||||||
if (!error.response) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rejectWithValue(error.response.data);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export const scoutingSlice = createSlice({
|
|
||||||
name: 'scouting',
|
|
||||||
initialState,
|
|
||||||
reducers: {
|
|
||||||
setRefetch: (state, action: PayloadAction<boolean>) => {
|
|
||||||
state.refetch = action.payload;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
extraReducers: (builder) => {
|
|
||||||
builder.addCase(fetch.pending, (state) => {
|
|
||||||
state.loading = true;
|
|
||||||
resetNotify(state);
|
|
||||||
});
|
|
||||||
builder.addCase(fetch.rejected, (state, action) => {
|
|
||||||
state.loading = false;
|
|
||||||
rejectNotify(state, action);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(fetch.fulfilled, (state, action) => {
|
|
||||||
if (action.payload.rows && action.payload.count >= 0) {
|
|
||||||
state.scouting = action.payload.rows;
|
|
||||||
state.count = action.payload.count;
|
|
||||||
} else {
|
|
||||||
state.scouting = action.payload;
|
|
||||||
}
|
|
||||||
state.loading = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(deleteItemsByIds.pending, (state) => {
|
|
||||||
state.loading = true;
|
|
||||||
resetNotify(state);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(deleteItemsByIds.fulfilled, (state) => {
|
|
||||||
state.loading = false;
|
|
||||||
fulfilledNotify(state, 'Scouting has been deleted');
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(deleteItemsByIds.rejected, (state, action) => {
|
|
||||||
state.loading = false;
|
|
||||||
rejectNotify(state, action);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(deleteItem.pending, (state) => {
|
|
||||||
state.loading = true;
|
|
||||||
resetNotify(state);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(deleteItem.fulfilled, (state) => {
|
|
||||||
state.loading = false;
|
|
||||||
fulfilledNotify(state, `${'Scouting'.slice(0, -1)} has been deleted`);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(deleteItem.rejected, (state, action) => {
|
|
||||||
state.loading = false;
|
|
||||||
rejectNotify(state, action);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(create.pending, (state) => {
|
|
||||||
state.loading = true;
|
|
||||||
resetNotify(state);
|
|
||||||
});
|
|
||||||
builder.addCase(create.rejected, (state, action) => {
|
|
||||||
state.loading = false;
|
|
||||||
rejectNotify(state, action);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(create.fulfilled, (state) => {
|
|
||||||
state.loading = false;
|
|
||||||
fulfilledNotify(state, `${'Scouting'.slice(0, -1)} has been created`);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(update.pending, (state) => {
|
|
||||||
state.loading = true;
|
|
||||||
resetNotify(state);
|
|
||||||
});
|
|
||||||
builder.addCase(update.fulfilled, (state) => {
|
|
||||||
state.loading = false;
|
|
||||||
fulfilledNotify(state, `${'Scouting'.slice(0, -1)} has been updated`);
|
|
||||||
});
|
|
||||||
builder.addCase(update.rejected, (state, action) => {
|
|
||||||
state.loading = false;
|
|
||||||
rejectNotify(state, action);
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCase(uploadCsv.pending, (state) => {
|
|
||||||
state.loading = true;
|
|
||||||
resetNotify(state);
|
|
||||||
});
|
|
||||||
builder.addCase(uploadCsv.fulfilled, (state) => {
|
|
||||||
state.loading = false;
|
|
||||||
fulfilledNotify(state, 'Scouting has been uploaded');
|
|
||||||
});
|
|
||||||
builder.addCase(uploadCsv.rejected, (state, action) => {
|
|
||||||
state.loading = false;
|
|
||||||
rejectNotify(state, action);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Action creators are generated for each case reducer function
|
|
||||||
export const { setRefetch } = scoutingSlice.actions;
|
|
||||||
|
|
||||||
export default scoutingSlice.reducer;
|
|
||||||
@ -11,7 +11,6 @@ import scouting_dataSlice from './scouting_data/scouting_dataSlice';
|
|||||||
import tasksSlice from './tasks/tasksSlice';
|
import tasksSlice from './tasks/tasksSlice';
|
||||||
import rolesSlice from './roles/rolesSlice';
|
import rolesSlice from './roles/rolesSlice';
|
||||||
import permissionsSlice from './permissions/permissionsSlice';
|
import permissionsSlice from './permissions/permissionsSlice';
|
||||||
import scoutingSlice from './scouting/scoutingSlice';
|
|
||||||
|
|
||||||
export const store = configureStore({
|
export const store = configureStore({
|
||||||
reducer: {
|
reducer: {
|
||||||
@ -27,7 +26,6 @@ export const store = configureStore({
|
|||||||
tasks: tasksSlice,
|
tasks: tasksSlice,
|
||||||
roles: rolesSlice,
|
roles: rolesSlice,
|
||||||
permissions: permissionsSlice,
|
permissions: permissionsSlice,
|
||||||
scouting: scoutingSlice,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user