cleanup , header & logo
This commit is contained in:
@@ -1,125 +0,0 @@
|
||||
class CoachingAdminModel extends EICModel {
|
||||
|
||||
organisations = [
|
||||
{
|
||||
pic: '789654123',
|
||||
legalname: 'NightSHift.be',
|
||||
projects: [
|
||||
{
|
||||
reference: 1,
|
||||
number: '965432187',
|
||||
type: 'project',
|
||||
acronym: 'Total Pepet 3000',
|
||||
organisation: 'ACME inc.',
|
||||
status: 'coach selected',
|
||||
creditsUsed: 3,
|
||||
creditsLeft: 3
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
pic: '896754312',
|
||||
legalname: 'ACME inc.',
|
||||
projects: [
|
||||
{
|
||||
reference: 1,
|
||||
number: '965432187',
|
||||
type: 'project',
|
||||
acronym: 'Total Pepet 2000',
|
||||
organisation: 'ACME inc.',
|
||||
status: 'coach selected',
|
||||
creditsUsed: 3,
|
||||
creditsLeft: 3
|
||||
},
|
||||
{
|
||||
reference: 1,
|
||||
number: '965432187',
|
||||
type: 'project',
|
||||
acronym: 'MAXIBROUZOUF',
|
||||
organisation: 'ACME inc.',
|
||||
status: 'closed',
|
||||
creditsUsed: 3,
|
||||
creditsLeft: 3
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
/**
|
||||
*
|
||||
*/
|
||||
getCoachings() {
|
||||
return Promise.resolve([
|
||||
{
|
||||
reference: 1,
|
||||
number: '987654321',
|
||||
type: 'proposal',
|
||||
acronym: 'MAXIBROUZOUF',
|
||||
organisation: 'ACME inc.',
|
||||
status: 'closed',
|
||||
creditsUsed: 6,
|
||||
creditsLeft: 0
|
||||
},
|
||||
{
|
||||
reference: 1,
|
||||
number: '965432187',
|
||||
type: 'project',
|
||||
acronym: 'Total Pepet 2000',
|
||||
organisation: 'ACME inc.',
|
||||
status: 'coach selected',
|
||||
creditsUsed: 3,
|
||||
creditsLeft: 3
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
getCoaching(number, id) { return Promise.resolve({ }); }
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
getCompanies() { return Promise.resolve(this.organisations); }
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
getOrganisation(pic) { return this.organisations.find(item => item.pic == pic); }
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
getCoaches() {
|
||||
return Promise.resolve([
|
||||
{
|
||||
id: 12345,
|
||||
uid: 'fallimi',
|
||||
firstname: 'Michael',
|
||||
lastname: 'Fallise',
|
||||
email: 'michael.fallise@gmail.com',
|
||||
invitations: 2,
|
||||
coachings: 3
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
getCoach(id) {
|
||||
return Promise.resolve(
|
||||
{
|
||||
id: 12345,
|
||||
firstname: 'Michael',
|
||||
lastname: 'Fallise',
|
||||
email: 'michael.fallise@gmail.com',
|
||||
phone: '+32477708551',
|
||||
address: '',
|
||||
coachings: 3
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('CoachingAdminModel',CoachingAdminModel);
|
||||
@@ -1,5 +0,0 @@
|
||||
class CoachingApplicantModel extends EICModel {
|
||||
|
||||
}
|
||||
|
||||
app.registerClass('CoachingApplicantModel',CoachingApplicantModel);
|
||||
@@ -1,58 +0,0 @@
|
||||
class CoachingCoachModel extends EICModel {
|
||||
|
||||
getInvitations() {
|
||||
return Promise.resolve([
|
||||
{
|
||||
id: 1,
|
||||
status: 'invitations-sent',
|
||||
proposal: {
|
||||
number: '9876545421',
|
||||
acronym: 'MAXIBROUZOUF'
|
||||
},
|
||||
priorities: {
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
status: 'invitations-sent',
|
||||
proposal: {
|
||||
number: '9876421545',
|
||||
acronym: 'Inno Pepet 2000'
|
||||
},
|
||||
priorities: {
|
||||
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
getCoachings() {
|
||||
return Promise.resolve([
|
||||
{
|
||||
id: 1,
|
||||
status: 'closed',
|
||||
proposal: {
|
||||
number: '9876545421',
|
||||
acronym: 'MAXIBROUZOUF'
|
||||
},
|
||||
priorities: {
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
status: 'plan-approved',
|
||||
proposal: {
|
||||
number: '9876421545',
|
||||
acronym: 'Inno Pepet 2000'
|
||||
},
|
||||
priorities: {
|
||||
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('CoachingCoachModel',CoachingCoachModel);
|
||||
@@ -1,83 +0,0 @@
|
||||
class ContactMgrModel extends EICModel {
|
||||
|
||||
constructor(privileges) {
|
||||
super('/contactMgr', privileges)
|
||||
Object.assign(this, app.helpers.validators)
|
||||
}
|
||||
|
||||
async list() {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('list')
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async get(qcid){
|
||||
if(!this.hasPrivilege('get')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('get')
|
||||
endpoint.uri = endpoint.uri.replace('{qcid}', qcid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async getField(qcid, fieldid){
|
||||
if(!this.hasPrivilege('getFields')) return( new Promise((resolve, reject) => reject()))
|
||||
const endpoint = this.getApiEndpoint('getFields')
|
||||
endpoint.uri = endpoint.uri.replace('{qcid}', qcid)
|
||||
const payload = {
|
||||
fieldid: fieldid
|
||||
}
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, payload)
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async getSample(qcid, values){
|
||||
if(!this.hasPrivilege('execute')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('execute')
|
||||
endpoint.uri = endpoint.uri.replace('{qcid}', qcid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, {
|
||||
sample: true,
|
||||
sampleSize: 10,
|
||||
values: values,
|
||||
})
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async execute(qcid, values){
|
||||
if(!this.hasPrivilege('execute')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('execute')
|
||||
endpoint.uri = endpoint.uri.replace('{qcid}', qcid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, {
|
||||
sample: false,
|
||||
values: values,
|
||||
})
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async probe(qcid, values, probe){
|
||||
if(!this.hasPrivilege('execute')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('execute')
|
||||
endpoint.uri = endpoint.uri.replace('{qcid}', qcid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, {
|
||||
sample: false,
|
||||
probe: probe,
|
||||
values: values,
|
||||
})
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
app.registerClass('ContactMgrModel', ContactMgrModel);
|
||||
@@ -1,427 +0,0 @@
|
||||
class MailingsModel extends EICModel {
|
||||
|
||||
constructor(privileges) {
|
||||
super('/mailing', privileges)
|
||||
this.ffs = new FakeFileSystem()
|
||||
Object.assign(this, app.helpers.validators)
|
||||
}
|
||||
|
||||
async search(query, status=[]) {
|
||||
if(!this.hasPrivilege('search')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('search')
|
||||
let payload = {
|
||||
query: query,
|
||||
status: status,
|
||||
}
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, payload) // Separate filesystem info from true mailings
|
||||
.then( async serverData => serverData.payload)
|
||||
.then( data => { // And feed ffs
|
||||
this.ffs.loadStructure(
|
||||
data.ffs,
|
||||
data.mailings.map(item=>(
|
||||
{
|
||||
fullPath: (item.path+'/'+item.name).replace(/\/+/g, '/'),
|
||||
object : item
|
||||
}
|
||||
))
|
||||
)
|
||||
return(data.mailings)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
async get(mid) {
|
||||
if(!this.hasPrivilege('read')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('read')
|
||||
endpoint.uri = endpoint.uri.replace('{mid}', mid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async getRecipients(mid){
|
||||
if(!this.hasPrivilege('read')) return( new Promise((resolve, reject) => reject())) // if can read mailing => can read recipients
|
||||
let endpoint = this.getApiEndpoint('read', '/mailing/{mid}/recipients')
|
||||
endpoint.uri = endpoint.uri.replace('{mid}', mid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async getBounces(mid){
|
||||
if(!this.hasPrivilege('read')) return( new Promise((resolve, reject) => reject())) // if can read mailing => can read bounces
|
||||
let endpoint = this.getApiEndpoint('read', '/mailing/{mid}/bounces')
|
||||
endpoint.uri = endpoint.uri.replace('{mid}', mid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async save(mailingInfo) {
|
||||
// Local copy where we'll remove display (non-save-able) mailingInfo stuff, and join-in ext stuff into the request.
|
||||
let localMmailingInfo = JSON.parse(JSON.stringify(mailingInfo))
|
||||
|
||||
// template struct => templateId
|
||||
if(localMmailingInfo.template && localMmailingInfo.template.id){
|
||||
localMmailingInfo.templateId = localMmailingInfo.template.id
|
||||
delete(localMmailingInfo.template)
|
||||
}
|
||||
|
||||
delete(localMmailingInfo.imports)
|
||||
delete(localMmailingInfo.sources)
|
||||
delete(localMmailingInfo.statusHistory)
|
||||
delete(localMmailingInfo.kpis)
|
||||
delete(localMmailingInfo.nbSources)
|
||||
delete(localMmailingInfo.nbRecipients)
|
||||
|
||||
let endpoint = this.getApiEndpoint('save')
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, localMmailingInfo)
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async delete(mid) {
|
||||
if(!this.hasPrivilege('delete')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('delete')
|
||||
endpoint.uri = endpoint.uri.replace('{mid}', mid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async schedule(mid, scheduleDate) {
|
||||
if(!this.hasPrivilege('schedule')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('schedule')
|
||||
endpoint.uri = endpoint.uri.replace('{mid}', mid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, { scheduleDate: scheduleDate })
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async test(mid, templateId, recipientEmail, mappings={}) {
|
||||
if((!this.hasPrivilege('edit')) && (!this.hasPrivilege('approve')) && (!this.hasPrivilege('reject'))) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('test')
|
||||
endpoint.uri = endpoint.uri.replace('{mid}', mid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, {
|
||||
templateId: templateId,
|
||||
recipientEmail: recipientEmail,
|
||||
parameters: mappings
|
||||
})
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async getImports(mid) {
|
||||
let endpoint = this.getApiEndpoint('list', '/mailing/{mid}/imports')
|
||||
endpoint.uri = endpoint.uri.replace('{mid}', mid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async saveImport(mid, data) {
|
||||
data.refresh = false
|
||||
let endpoint = this.getApiEndpoint('save', '/mailing/{mid}/imports')
|
||||
endpoint.uri = endpoint.uri.replace('{mid}', mid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, data)
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async saveExclusion(mid, data) {
|
||||
data.refresh = false
|
||||
data.exclusionList = true
|
||||
data.availableColumns = data.availableColumns.filter(item=>item.isEmail)
|
||||
const emailIdx = data.availableColumns[0].value
|
||||
data.data = data.data.map(row=>row[emailIdx])
|
||||
let endpoint = this.getApiEndpoint('save', '/mailing/{mid}/imports')
|
||||
endpoint.uri = endpoint.uri.replace('{mid}', mid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, data)
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async refreshImport(mid, data, importId) {
|
||||
if(data.sourceType=='Excel') return({})
|
||||
data.refresh = true
|
||||
data.importId = importId
|
||||
let endpoint = this.getApiEndpoint('save', '/mailing/{mid}/imports')
|
||||
endpoint.uri = endpoint.uri.replace('{mid}', mid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, data)
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async readImport(mid, iid) {
|
||||
let endpoint = this.getApiEndpoint('read', '/mailing/{mid}/imports/{iid}')
|
||||
endpoint.uri = endpoint.uri.replace('{mid}', mid).replace('{iid}', iid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async deleteImport(mid, id) {
|
||||
let endpoint = this.getApiEndpoint('delete', '/mailing/{mid}/imports')
|
||||
endpoint.uri = endpoint.uri.replace('{mid}', mid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, { id: id })
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async getReadableFolders() {
|
||||
try {
|
||||
const endpoint = this.getApiEndpoint('list', '/mailing/folders')
|
||||
const payload = { path: '/', withFiles: true }
|
||||
|
||||
const serverData = await this.request(endpoint.uri, endpoint.method, payload)
|
||||
return serverData.payload || {}
|
||||
} catch (err) {
|
||||
console.error("Error in getReadableFolders", err)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async makeDir(path=null, dirName){
|
||||
let ffs = this.ffs
|
||||
if(path && (!ffs.pathExists(path))) return(Promise.resolve(null))
|
||||
if(!path) path=ffs.currentPath
|
||||
dirName = dirName.replace(/\//g,'').replace(/"/g,'').replace('\\','').replace(/\./g,'')
|
||||
|
||||
let endpoint = this.getApiEndpoint('add', '/mailing/folders')
|
||||
let uri = endpoint.uri
|
||||
return (
|
||||
this.request(uri, endpoint.method, {
|
||||
appId: 2,
|
||||
path: path,
|
||||
newFolder: dirName
|
||||
})
|
||||
.then( async serverData => {
|
||||
return(serverData.payload)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
async removeDir(appId, path = null) {
|
||||
let ffs = this.ffs
|
||||
if (!path) return Promise.resolve(null)
|
||||
|
||||
path = ffs.normalizePath(path)
|
||||
|
||||
let endpoint = this.getApiEndpoint('delete', '/mailing/folders')
|
||||
let uri = endpoint.uri
|
||||
|
||||
|
||||
return this.request(uri, endpoint.method, {
|
||||
appId: appId,
|
||||
path: path
|
||||
}).then(async serverData => {
|
||||
return serverData.payload
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/********************************* Data helpers **************************************/
|
||||
getStatusLabel() {
|
||||
return({
|
||||
created : 'Created',
|
||||
draft : 'Draft',
|
||||
submitted : app.User.roles.includes('MAIL_Reviewer') ? 'To review' : 'Being reviewed',
|
||||
approved : 'Approved',
|
||||
rejected : 'Rejected',
|
||||
scheduled : 'Scheduled',
|
||||
sent : 'Sent',
|
||||
})
|
||||
}
|
||||
|
||||
findDupes(allImports){
|
||||
let dupes = {} //Key email, value: array of where it is found
|
||||
let allEmails = []
|
||||
for(let oneImport of allImports){
|
||||
const emailCol = oneImport.availableColumns.find(item => item.isEmail)
|
||||
if(!emailCol) continue
|
||||
for(let[rownb, row] of oneImport.data.entries()){
|
||||
let inAllEmails = allEmails.find(item => ( item.email == row[emailCol.value]))
|
||||
if(inAllEmails) { // that's a dupe
|
||||
if(!(row[emailCol.value] in dupes)) { // First time we come across this one, add the original entry
|
||||
dupes[row[emailCol.value]] = [{
|
||||
sourceName: inAllEmails.sourceName,
|
||||
sourceType: inAllEmails.sourceType,
|
||||
rownb: inAllEmails.rownb,
|
||||
}]
|
||||
}
|
||||
dupes[row[emailCol.value]].push({ // Add the dupe
|
||||
sourceName: oneImport.sourceName,
|
||||
sourceType: oneImport.sourceType,
|
||||
rownb: rownb,
|
||||
})
|
||||
} else {
|
||||
allEmails.push({
|
||||
email: row[emailCol.value],
|
||||
sourceName: oneImport.sourceName,
|
||||
sourceType : oneImport.sourceType,
|
||||
rownb: rownb,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return(dupes)
|
||||
}
|
||||
|
||||
getLatestStatus(mailingInfo, status=null){
|
||||
if(!mailingInfo || !mailingInfo.statusHistory || (mailingInfo.statusHistory.length<1)) return('')
|
||||
const latest = mailingInfo.statusHistory.reduce((max, obj) =>
|
||||
(obj.dateTime > max.dateTime) && ((!status) || (status==obj.value)) ? obj : max
|
||||
)
|
||||
return( (!status) ? latest : (status == latest.value) ? latest : null )
|
||||
}
|
||||
|
||||
getStepActivations(mailing, templateTokens){
|
||||
const stepActivations = { }
|
||||
stepActivations['start'] = {
|
||||
disabled: (!this.hasPrivilege('edit')) || ((mailing.status != 'created') && (mailing.status != 'draft')),
|
||||
severity: (mailing.status != 'created') ? 'success' : 'warning',
|
||||
done: (mailing.name && mailing.path)
|
||||
}
|
||||
stepActivations['template'] = {
|
||||
disabled: (!this.hasPrivilege('edit')) || (mailing.status != 'draft'),
|
||||
severity: (!mailing.template.id) ? (mailing.status != 'draft') ? 'secondary' : 'warning' : 'success',
|
||||
done: (mailing.template.id)
|
||||
}
|
||||
stepActivations['recipients'] = {
|
||||
disabled: (!this.hasPrivilege('edit')) || (mailing.status != 'draft'), // || (!stepActivations.template.done),
|
||||
severity: (mailing.nbRecipients == 0) ? ((mailing.status != 'draft') || (!mailing.template.id)) ? 'secondary' : 'warning' : 'success',
|
||||
done: (mailing.nbRecipients > 0)
|
||||
}
|
||||
stepActivations['mappings'] = {
|
||||
disabled: (!this.hasPrivilege('edit')) || (mailing.status != 'draft') || (!stepActivations.template.done) || (!stepActivations.recipients.done),
|
||||
severity: (stepActivations.template.done && stepActivations.recipients.done) ? (this.TotalNbMapMissing(mailing, templateTokens) > 0) ? 'warning': 'success' : 'secondary',
|
||||
done: (stepActivations['template'].done && stepActivations['recipients'].done && (this.TotalNbMapMissing(mailing, templateTokens) == 0))
|
||||
}
|
||||
stepActivations['approval'] = {
|
||||
disabled: ((!this.hasPrivilege('edit')) && (!this.hasPrivilege('approve')) && (!this.hasPrivilege('reject'))) || (!(['draft','submitted'].includes(mailing.status))) || (!stepActivations.mappings.done) ,
|
||||
severity: stepActivations.mappings.done ? ((mailing.status == 'approved') || (mailing.status == 'scheduled')) ? 'success' : 'warning' : 'secondary',
|
||||
done: (mailing.status == 'approved')
|
||||
}
|
||||
stepActivations['schedule'] = {
|
||||
disabled: (!this.hasPrivilege('schedule')) || ((mailing.status!='approved') && (mailing.status!='scheduled')),
|
||||
severity: (mailing.status!='scheduled') ? (mailing.status!='approved') ? 'secondary' : 'warning' : 'success',
|
||||
done: (mailing.status=='scheduled')
|
||||
}
|
||||
return(stepActivations)
|
||||
}
|
||||
|
||||
nbMapMissingPerSrc(mailing, templateTokens){
|
||||
let nbMissing = {}
|
||||
mailing.sources.forEach(src => {
|
||||
let srcMappings = mailing.mappings.find(mp => mp. sourceId==src.id)
|
||||
if(srcMappings) {
|
||||
nbMissing[src.id] = (templateTokens.length - Object.keys(srcMappings.mappings).length)
|
||||
} else {
|
||||
nbMissing[src.id] = templateTokens.length
|
||||
}
|
||||
})
|
||||
return(nbMissing)
|
||||
}
|
||||
|
||||
TotalNbMapMissing(mailing, templateTokens){
|
||||
const missingPerSrc = this.nbMapMissingPerSrc(mailing, templateTokens)
|
||||
return(Object.keys(missingPerSrc).reduce((acc,key) => acc+=missingPerSrc[key],0))
|
||||
}
|
||||
|
||||
getReviewBlocks(mailing){
|
||||
const latestSubmitted = this.getLatestStatus(mailing, 'submitted')
|
||||
const latestRejected = this.getLatestStatus(mailing, 'rejected')
|
||||
const latestApproved = this.getLatestStatus(mailing, 'approved')
|
||||
let blocks = []
|
||||
let contents = {}
|
||||
if(!app.User.roles.includes('MAIL_Reviewer')){
|
||||
// Only Editors & Revieers can sen test mails
|
||||
if(app.User.roles.includes('MAIL_Editor')) blocks.push('testPane')
|
||||
blocks.push('revieweePane')
|
||||
switch(mailing.status){
|
||||
case 'submitted': blocks.push('revieweeOngoing'); break
|
||||
case 'approved': blocks.push('revieweeApproved')
|
||||
contents['approUser1'] = `${latestApproved.changedBy.firstname} ${latestApproved.changedBy.lastname}`
|
||||
contents['approDate1'] = (new Intl.DateTimeFormat("fr-FR", {timeZone: "Europe/Paris", dateStyle:'medium', timeStyle:'medium'}))
|
||||
.format(new Date(latestApproved.dateTime))
|
||||
break
|
||||
case 'draft': if((latestRejected) && // no rejection ever
|
||||
// Rejection and no approval afterwards (possible because might be draft again after unscheduled)
|
||||
((!latestApproved) || (latestApproved.dateTime<latestRejected.dateTime))){
|
||||
blocks.push('revieweeRejected')
|
||||
contents['rejectionUser1'] = `${latestRejected.changedBy.firstname} ${latestRejected.changedBy.lastname}`
|
||||
contents['rejectionDate1'] = (new Intl.DateTimeFormat("fr-FR", {timeZone: "Europe/Paris", dateStyle:'medium', timeStyle:'medium'}))
|
||||
.format(new Date(latestRejected.dateTime))
|
||||
contents['rejectionReason1'] = (latestRejected.meta && latestRejected.meta.reason) ? latestRejected.meta.reason : ''
|
||||
} else if(app.User.roles.includes('MAIL_Editor')) {
|
||||
blocks.push('revieweeRequest')
|
||||
}
|
||||
break
|
||||
}
|
||||
} else {
|
||||
blocks.push('testPane')
|
||||
|
||||
switch(mailing.status){
|
||||
case 'submitted': blocks.push('reviewerPane')
|
||||
blocks.push('reviewerChoice')
|
||||
contents['requestUser2'] =`${latestSubmitted.changedBy.firstname} ${latestSubmitted.changedBy.lastname}`
|
||||
contents['requestDate2'] =(new Intl.DateTimeFormat("fr-FR", {timeZone: "Europe/Paris", dateStyle:'medium', timeStyle:'medium'}))
|
||||
.format(new Date(latestSubmitted.dateTime))
|
||||
contents['reviewComments2'] = (latestSubmitted.meta && latestSubmitted.meta.comments) ? latestSubmitted.meta.comments : ''
|
||||
break
|
||||
case 'approved': blocks.push('reviewerPane')
|
||||
blocks.push('reviewerApproved')
|
||||
contents['approUser2'] = `${latestApproved.changedBy.firstname} ${latestApproved.changedBy.lastname}`
|
||||
contents['approDate2'] = (new Intl.DateTimeFormat("fr-FR", {timeZone: "Europe/Paris", dateStyle:'medium', timeStyle:'medium'}))
|
||||
.format(new Date(latestApproved.dateTime))
|
||||
break
|
||||
case 'draft': if(app.User.roles.includes('MAIL_Editor')) {
|
||||
// For those who are both editor & reviewer, let them ask themselves (or other reviewer)
|
||||
blocks.push('revieweePane')
|
||||
blocks.push('revieweeRequest')
|
||||
}
|
||||
if((latestRejected) &&
|
||||
// Rejection and no approval afterwards (possible because might be draft again after unscheduled)
|
||||
((!latestApproved) || (latestApproved.dateTime<latestRejected.dateTime))){
|
||||
blocks.push('reviewerPane')
|
||||
blocks.push('reviewerRejected')
|
||||
contents['rejectionUser2'] = `${latestRejected.changedBy.firstname} ${latestRejected.changedBy.lastname}`
|
||||
contents['rejectionDate2'] = (new Intl.DateTimeFormat("fr-FR", {timeZone: "Europe/Paris", dateStyle:'medium', timeStyle:'medium'}))
|
||||
.format(new Date(latestRejected.dateTime))
|
||||
contents['rejectionReason2'] = (latestRejected.meta && latestRejected.meta.reason) ? latestRejected.meta.reason : ''
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return([blocks, contents])
|
||||
}
|
||||
|
||||
canImport(){
|
||||
return(true)
|
||||
}
|
||||
|
||||
canImportExclusion(){
|
||||
return(true)
|
||||
}
|
||||
|
||||
canFetch(){
|
||||
return(app.User.identity.uuid=='steinic')
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('MailingsModel', MailingsModel);
|
||||
@@ -1,315 +0,0 @@
|
||||
class TemplatesModel extends EICModel {
|
||||
|
||||
current = null;
|
||||
|
||||
constructor(privileges) {
|
||||
super('/templates', privileges)
|
||||
this.ffs = new FakeFileSystem()
|
||||
this.tokenCache = {}
|
||||
}
|
||||
|
||||
getLatestStatus(templateInfo, status=null){
|
||||
if(!templateInfo.statusHistory || (templateInfo.statusHistory.length<1)) return('')
|
||||
return(
|
||||
templateInfo.statusHistory.reduce((max, obj) =>
|
||||
(obj.dateTime > max.dateTime) && ((!status) || (status==obj.value)) ? obj : max
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
getTokens(templateInfo){
|
||||
if((!templateInfo) || (!templateInfo.id)) return
|
||||
if(templateInfo.id in this.tokenCache) return(this.tokenCache[templateInfo.id])
|
||||
const re = new RegExp(/\{\{([\w\-\.\^\#\/]+)\}\}/,'gm')
|
||||
let txt = atob(templateInfo.html)
|
||||
let allTokens = [...txt.matchAll(re)].map(item=>item[1])
|
||||
if(templateInfo.meta.altText){
|
||||
txt = atob(templateInfo.meta.altText)
|
||||
for(let m of txt.matchAll(re)){
|
||||
if(!allTokens.includes(m[1])) allTokens.push(m[1])
|
||||
}
|
||||
}
|
||||
if(templateInfo.meta.subject){
|
||||
txt = templateInfo.meta.subject
|
||||
for(let m of txt.matchAll(re)){
|
||||
if(!allTokens.includes(m[1])) allTokens.push(m[1])
|
||||
}
|
||||
}
|
||||
this.tokenCache[templateInfo.id] = allTokens
|
||||
return(allTokens)
|
||||
}
|
||||
|
||||
countTokens(templateInfo){
|
||||
return(this.getTokens(templateInfo).length)
|
||||
}
|
||||
|
||||
async getTechDDTokens() {
|
||||
this.tokenList = Promise.resolve([
|
||||
{ name: 'personEmail' },
|
||||
{ name: 'personEuLogin' },
|
||||
{ name: 'personFirstName' },
|
||||
{ name: 'personLastName' },
|
||||
{ name: 'personFullName' },
|
||||
{ name: 'organisationFullName' },
|
||||
{ name: 'organisationShortName' },
|
||||
{ name: 'organisationPIC' },
|
||||
{ name: 'proposalId' },
|
||||
{ name: 'proposalAcronym' },
|
||||
{ name: 'proposalType' },
|
||||
{ name: 'expertFirstName' },
|
||||
{ name: 'expertLastName' },
|
||||
{ name: 'expertFullName' },
|
||||
{ name: 'FIOFirstName' },
|
||||
{ name: 'FIOLastName' },
|
||||
{ name: 'FIOFullName' },
|
||||
{ name: 'POFirstName' },
|
||||
{ name: 'POLastName' },
|
||||
{ name: 'POFullName' },
|
||||
{ name: 'TechDDFirstName' },
|
||||
{ name: 'TechDDLastName' },
|
||||
{ name: 'TechDDFullName' },
|
||||
{ name: 'reportURL' },
|
||||
{ name: 'unsubscribeURL' }
|
||||
]);
|
||||
return this.tokenList;
|
||||
}
|
||||
|
||||
/************************/
|
||||
|
||||
|
||||
/**
|
||||
* Get a template by its ID.
|
||||
* @param {string} tid - The ID of the templitor.
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
async get(tid) {
|
||||
let endpoint = this.getApiEndpoint('read')
|
||||
endpoint.uri = endpoint.uri.replace('{tid}', tid)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* List all templates.
|
||||
* @returns {Promise<any[]>}
|
||||
*/
|
||||
async search(query, status=[]) {
|
||||
if(!this.hasPrivilege('search')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('search')
|
||||
let payload = {
|
||||
query: query,
|
||||
status: status,
|
||||
}
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, payload)
|
||||
.then( async serverData => serverData.payload)
|
||||
.then( data => {
|
||||
this.ffs.loadStructure(
|
||||
data.ffs,
|
||||
data.templates.map(item=>(
|
||||
{
|
||||
fullPath: (item.path+'/'+item.name).replace(/\/+/g, '/'),
|
||||
object : item
|
||||
}
|
||||
))
|
||||
)
|
||||
return(data.templates)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
async save(data) {
|
||||
let endpoint = this.getApiEndpoint('save')
|
||||
console.log("Saving template with data:", data);
|
||||
return this.request(endpoint.uri, endpoint.method, data)
|
||||
}
|
||||
|
||||
async delete(tid) {
|
||||
if(!this.hasPrivilege('delete')) return( new Promise((reject) => reject('Insufficient privileges to perform delete templates')))
|
||||
let endpoint = this.getApiEndpoint('delete')
|
||||
endpoint.uri = endpoint.uri.replace('{tid}', tid)
|
||||
return this.request(endpoint.uri, endpoint.method)
|
||||
}
|
||||
|
||||
/*
|
||||
* list of predefined images can be used in template
|
||||
*/
|
||||
async getImages() {
|
||||
if(!this.hasPrivilege('read')) return( new Promise((reject) => reject('Insufficient privileges to perform get images'))) // if can read templates => can search list
|
||||
let endpoint = this.getApiEndpoint('getImages');
|
||||
return this.request(endpoint.uri, endpoint.method)
|
||||
.then(serverData => serverData.payload)
|
||||
.then(data => {
|
||||
return data.map(item => ({
|
||||
fullPath: (item.path + '/' + item.name).replace(/\/+/g, '/'),
|
||||
object: item,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete image
|
||||
* @param {*} pid - picture id
|
||||
* @param {*} deleteUrl - aws image url
|
||||
* @returns {Promise<any[]>}
|
||||
*/
|
||||
async deleteImage(pid, deleteUrl) {
|
||||
if (!this.hasPrivilege('delete')) {
|
||||
return new Promise((reject) => reject('Insufficient privileges to perform delete images'));
|
||||
}
|
||||
|
||||
let endpoint = this.getApiEndpoint('deleteImage');
|
||||
endpoint.uri = endpoint.uri.replace('{pid}', pid);
|
||||
|
||||
const requestBody = { deleteUrl: deleteUrl };
|
||||
|
||||
return this.request(endpoint.uri, endpoint.method, requestBody)
|
||||
.then(response => {
|
||||
console.log('Image deleted successfully:', response);
|
||||
return response;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error deleting image:', error);
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
getStatusLabel() {
|
||||
return({
|
||||
created : 'Created',
|
||||
draft : 'Draft',
|
||||
submitted : app.User.roles.includes('TEMPLATE_Reviewer') ? 'To review' : 'Being reviewed',
|
||||
prod : 'Approved',
|
||||
archived : 'Archived',
|
||||
})
|
||||
}
|
||||
|
||||
async readDir(path = '/', withFiles=true ){
|
||||
if(!this.hasPrivilege('read')) return( new Promise((reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('list', '/templitor/folders')
|
||||
let uri = endpoint.uri
|
||||
return (
|
||||
this.request(uri, endpoint.method, { "path":path, withFiles: true })
|
||||
.then( async serverData => {
|
||||
if(!withFiles){
|
||||
this.ffs.changeDir('/')
|
||||
this.ffs.loadStructure(serverData.payload, this.ffs.getFiles())
|
||||
} else {
|
||||
const ffsData = serverData.payload.ffs || serverData.payload
|
||||
this.ffs.loadStructure(ffsData, serverData.payload.files || [])
|
||||
}
|
||||
return(serverData.payload)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
async getReadableFolders() {
|
||||
try {
|
||||
const endpoint = this.getApiEndpoint('list', '/templitor/folders')
|
||||
const payload = { path: '/', withFiles: true }
|
||||
|
||||
const serverData = await this.request(endpoint.uri, endpoint.method, payload)
|
||||
return serverData.payload || {}
|
||||
} catch (err) {
|
||||
console.error("Error in getReadableFolders", err)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async makeDir(path=null, dirName){
|
||||
let ffs = this.ffs //here not first param of method
|
||||
if(path && (!ffs.pathExists(path))) return(Promise.resolve(null))
|
||||
if(!path) path=ffs.currentPath
|
||||
dirName = dirName.replace(/\//g,'').replace(/"/g,'').replace('\\','').replace(/\./g,'')
|
||||
|
||||
let endpoint = this.getApiEndpoint('add', '/templitor/folders');
|
||||
let uri = endpoint.uri
|
||||
return (
|
||||
this.request(uri, endpoint.method, {
|
||||
appId: 1,
|
||||
path: path,
|
||||
newFolder: dirName
|
||||
})
|
||||
.then( async serverData => {
|
||||
return(serverData.payload)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
async removeDir(appId, path = null) {
|
||||
let ffs = this.ffs
|
||||
if (!path) return Promise.resolve(null)
|
||||
|
||||
path = ffs.normalizePath(path)
|
||||
|
||||
let endpoint = this.getApiEndpoint('delete', '/templitor/folders')
|
||||
let uri = endpoint.uri
|
||||
|
||||
|
||||
return this.request(uri, endpoint.method, {
|
||||
appId: appId,
|
||||
path: path
|
||||
}).then(async serverData => {
|
||||
return serverData.payload
|
||||
})
|
||||
}
|
||||
|
||||
async testMail(templateId, recipientEmail) {
|
||||
if(!this.hasPrivilege('edit')) return( new Promise((reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('testTemplateMail')
|
||||
endpoint.uri = endpoint.uri.replace('{tid}',templateId)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, {
|
||||
templateId: templateId,
|
||||
recipientEmail: recipientEmail
|
||||
})
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async saveImage(data) {
|
||||
let endpoint = this.getApiEndpoint('addImage');
|
||||
return this.request(endpoint.uri, endpoint.method, data);
|
||||
}
|
||||
|
||||
async requestPub(templateId, recipientEmail) {
|
||||
if(!this.hasPrivilege('edit')) return( new Promise((reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('requestPubTemplate')
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, {
|
||||
templateId: templateId,
|
||||
recipientEmail: recipientEmail
|
||||
})
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async approvePub(templateId, recipientEmail) {
|
||||
if((!this.hasPrivilege('edit')) && (!this.hasPrivilege('approve')) && (!this.hasPrivilege('reject'))) return( new Promise((reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('approvePub')
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, {
|
||||
templateId: templateId,
|
||||
recipientEmail: recipientEmail
|
||||
})
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
async rejectPub(templateId, recipientEmail) {
|
||||
if((!this.hasPrivilege('edit')) && (!this.hasPrivilege('approve')) && (!this.hasPrivilege('reject'))) return( new Promise((reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('rejectPub')
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, {
|
||||
templateId: templateId,
|
||||
recipientEmail: recipientEmail
|
||||
})
|
||||
.then( async serverData => serverData.payload)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
app.registerClass('TemplatesModel', TemplatesModel);
|
||||
@@ -1,235 +0,0 @@
|
||||
class BypassTokensModel extends EICPluralModel {
|
||||
|
||||
freeTokens = 0;
|
||||
|
||||
constructor(privileges) {
|
||||
|
||||
super('tokens', privileges);
|
||||
|
||||
this.singletonClass = class {
|
||||
itemData = {
|
||||
id: null,
|
||||
granted: null,
|
||||
track: null,
|
||||
domain: null,
|
||||
subdomain: null,
|
||||
enterprise: null,
|
||||
project: null,
|
||||
history: null,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sanitize(item) {
|
||||
item.history.sort((a,b) => a.dateTime < b.dateTime ? 1: -1);
|
||||
item.status = item.history[0].status;
|
||||
for(let entry of item.history) {
|
||||
if(entry.actor && entry.actor.lastname == 'Application User') {
|
||||
entry.actor.lastname = entry.actor.firstname;
|
||||
entry.actor.firstname = null;
|
||||
}
|
||||
}
|
||||
item.enterprise.pic = item.enterprise.pic || '(not provided)';
|
||||
item.enterprise.legalname = item.enterprise.legalname || '(not provided)';
|
||||
// fuck PI
|
||||
if(item.project && item.project.submissiondate) {
|
||||
item.project.submissionDate = item.project.submissiondate;
|
||||
delete item.project.submissiondate;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} filters
|
||||
* @returns
|
||||
*/
|
||||
list(filters) {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('list');
|
||||
this.collection = [];
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, filters)
|
||||
.then( async serverData => {
|
||||
const payload = serverData.payload;
|
||||
this.freeTokens = payload.countOfTokens;
|
||||
this.fill(payload.tokens);
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} filters
|
||||
* @returns
|
||||
*/
|
||||
export(filters) {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('list');
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, filters)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
getSettings(track) {
|
||||
if(!this.hasPrivilege('getSettings')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('getSettings');
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, {track: track})
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
setSettings(payload) {
|
||||
if(!this.hasPrivilege('setSettings')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('setSettings');
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, payload)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
getPrograms(track, domain) {
|
||||
if(!this.hasPrivilege('getPrograms')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = app.config.api.programs['getPrograms'];
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, {domain: domain, track: track})
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
addProgram(payload) {
|
||||
if(!this.hasPrivilege('addProgram')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = app.config.api.programs['addProgram'];
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, payload)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
removeProgram(payload) {
|
||||
if(!this.hasPrivilege('removeProgram')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = app.config.api.programs['removeProgram'];
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, payload)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the list of awarded tokens
|
||||
*
|
||||
* @returns array
|
||||
*/
|
||||
awardedTokens(year) {
|
||||
return (
|
||||
this.collection.filter(
|
||||
item => (['allocated','consumed'].includes(item.itemData.status))
|
||||
&& (new Date(item.itemData.granted).getFullYear() == year))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the list of consumed tokens
|
||||
*
|
||||
* @returns array
|
||||
*/
|
||||
consumedTokens(year) {
|
||||
return (
|
||||
this.collection.filter(
|
||||
item => (['consumed'].includes(item.itemData.status))
|
||||
&& (new Date(item.itemData.granted).getFullYear() == year))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a light-proposal for saving+submission+consume token
|
||||
*/
|
||||
viewToken(id) {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = JSON.parse(JSON.stringify(app.config.api.tokens.view))
|
||||
endpoint.uri = endpoint.uri.replace('{tokenid}', id);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a light-proposal for saving+submission+consume token
|
||||
*/
|
||||
consumeToken(payload) {
|
||||
if(!this.hasPrivilege('assign')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = app.config.api.tokens.assign
|
||||
endpoint.uri = endpoint.uri.replace('{pic}', payload.organisation.pic);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, payload)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the history (log) of all token actions
|
||||
*
|
||||
* @returns array
|
||||
*/
|
||||
history() {
|
||||
let dataset = [];
|
||||
for(let item of this.collection) {
|
||||
if(item.itemData.history.find(entry => entry.status == 'allocated')) {
|
||||
for(let entry of item.itemData.history) {
|
||||
if(entry.status != 'created' && entry.status != 'active') {
|
||||
dataset.push({
|
||||
date: entry.dateTime,
|
||||
pic: item.itemData.enterprise.pic,
|
||||
legalname: item.itemData.enterprise.legalname,
|
||||
action: entry.status,
|
||||
actor: entry.actor
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return dataset.sort((a,b) => a.date < b.date ? 1: -1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
app.registerClass('BypassTokensModel',BypassTokensModel);
|
||||
@@ -1,123 +0,0 @@
|
||||
class ApplicantMembersModel extends EICModel {
|
||||
|
||||
members = [];
|
||||
|
||||
constructor(privileges) {
|
||||
super('/organisations/{pic}/members', privileges);
|
||||
}
|
||||
|
||||
list(pic) {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
this.members = [];
|
||||
|
||||
let endpoint = this.getApiEndpoint('list');
|
||||
let uri = endpoint.uri.replace('{pic}', pic);
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
this.members = serverData.payload;
|
||||
return this.members;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
read(pic, uid) {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
//let endpoint = this.getApiEndpoint('list');
|
||||
//let uri = endpoint.uri.replace('{pic}', pic) + '/' + uid;
|
||||
|
||||
return (new Promise((resolve) => resolve(this.members.find(member => member.uid == uid))))
|
||||
|
||||
/*
|
||||
return (
|
||||
|
||||
//this.request(uri, endpoint.method)
|
||||
//.then( async serverData => { return serverData.payload })
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
search(hint) {
|
||||
if(!this.hasPrivilege('add')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('search');
|
||||
let uri = endpoint.uri;
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, {'hint': hint })
|
||||
.then( async serverData => {
|
||||
let users = serverData.payload.map(x=> { // Cleanup keys starting with https://
|
||||
for(let k in x){
|
||||
if(k.substring(0,4)=='http') { x[k.substring(k.lastIndexOf('/')+1)]=x[k]; delete(x[k]);}
|
||||
} return(x);
|
||||
} )
|
||||
return(users);
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
|
||||
update(pic, uid, payload) {
|
||||
if(!this.hasPrivilege('update')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('update');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{uid}', uid);
|
||||
let organisationLink = '/applicant/{pic}'.replace('{pic}',pic)
|
||||
payload.organisationLink = organisationLink
|
||||
return (
|
||||
this.request(uri, endpoint.method, payload)
|
||||
.then( async serverData => { return serverData.payload; })
|
||||
);
|
||||
}
|
||||
|
||||
add(pic, uid, payload) {
|
||||
if(!this.hasPrivilege('add')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('add');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{uid}', uid);
|
||||
let organisationLink = '/applicant/{pic}'.replace('{pic}',pic)
|
||||
payload.organisationLink = organisationLink
|
||||
payload.status = 'active';
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, payload)
|
||||
.then( async serverData => { return serverData.payload; })
|
||||
);
|
||||
}
|
||||
|
||||
grant(pic, uid, payload) {
|
||||
if(!this.hasPrivilege('grant')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('grant');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{uid}', uid);
|
||||
let organisationLink = '/applicant/{pic}'.replace('{pic}',pic)
|
||||
payload.organisationLink = organisationLink
|
||||
payload.status = 'active';
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, payload)
|
||||
.then( async serverData => { return serverData.payload; })
|
||||
);
|
||||
}
|
||||
|
||||
revoke(pic, uid) {
|
||||
if(!this.hasPrivilege('revoke')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('revoke');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{uid}', uid);
|
||||
let payload = {
|
||||
organisationLink: '/applicant/{pic}'.replace('{pic}',pic),
|
||||
status: 'deleted'
|
||||
}
|
||||
return (
|
||||
this.request(uri, endpoint.method, payload)
|
||||
.then( async serverData => { return serverData.payload; })
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('ApplicantMembersModel', ApplicantMembersModel);
|
||||
@@ -1,151 +0,0 @@
|
||||
class ApplicantOrganisationModel extends EICModel {
|
||||
|
||||
constructor(privileges) {
|
||||
super('/organisations/{pic}', privileges);
|
||||
}
|
||||
|
||||
search(pic) {
|
||||
if(!this.hasPrivilege('search')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('search');
|
||||
let uri = endpoint.uri
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, {'search': pic })
|
||||
.then( async serverData => this.loadData(serverData.payload))
|
||||
)
|
||||
}
|
||||
|
||||
list() {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('list');
|
||||
let uri = endpoint.uri
|
||||
|
||||
return ( this.request(uri, endpoint.method, payload) );
|
||||
}
|
||||
|
||||
read(pic) {
|
||||
if(!this.hasPrivilege('read')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('read');
|
||||
let uri = endpoint.uri.replace('{pic}', pic);
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method)
|
||||
.then( async serverData => { return serverData.payload })
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
app.registerClass('ApplicantOrganisationModel', ApplicantOrganisationModel);
|
||||
|
||||
|
||||
class ApplicantOrganisationProposalsModel extends EICModel {
|
||||
|
||||
constructor(privileges) {
|
||||
super('/organisations/{pic}/proposals', privileges);
|
||||
}
|
||||
|
||||
sanitize(list) {
|
||||
for(let item of list) {
|
||||
if(['created', 'updated'].includes(item.status)) item.status = 'draft';
|
||||
if(['evaluation-finalised'].includes(item.status)) item.status = 'evaluated';
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
list(pic) {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('list');
|
||||
let uri = endpoint.uri.replace('{pic}', pic);
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method)
|
||||
.then( async serverData => { return this.sanitize(serverData.payload) })
|
||||
);
|
||||
}
|
||||
|
||||
search(pic, query) {
|
||||
if(!this.hasPrivilege('search')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('search');
|
||||
let uri = endpoint.uri.replace('{pic}', pic);
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, query)
|
||||
.then( async serverData => { return this.sanitize(serverData.payload) })
|
||||
)
|
||||
}
|
||||
|
||||
create(pic) {
|
||||
if(!this.hasPrivilege('create')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('create');
|
||||
let uri = endpoint.uri.replace('{pic}', pic);
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method)
|
||||
.then( async serverData => { return serverData.payload })
|
||||
)
|
||||
}
|
||||
|
||||
apply(pic, pid, uid) {
|
||||
if(!this.hasPrivilege('apply')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('apply');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{pid}', pid).replace('{uid}', uid);
|
||||
//TODO NIKE : should get it via app.Route.makelink() but that one seems outdated, doesn't work as expected on complex cases.
|
||||
// => it only searches in routes known (loaded) at time of call, not into the whole tree of possible routes
|
||||
// (which would be to crazy to recursively build... ) => refactor makelink & come back here ! GREP for proposalLink & organisationLink in models
|
||||
let proposalLink = '/organisations/{pic}/proposals/{pid}'.replace('{pic}',pic).replace('{pid}',pid)
|
||||
return (
|
||||
this.request(uri, endpoint.method, { status: 'pending', proposalLink: proposalLink})
|
||||
.then( async serverData => { return serverData.payload })
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('ApplicantOrganisationProposalsModel', ApplicantOrganisationProposalsModel);
|
||||
|
||||
class ApplicantOrganisationCoachingsModel extends EICModel {
|
||||
|
||||
constructor(privileges) {
|
||||
super('/organisations/{pic}/coachings', privileges);
|
||||
}
|
||||
|
||||
sanitize(list) {
|
||||
for(let item of list) {
|
||||
if(['created', 'updated'].includes(item.status)) item.status = 'draft';
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
list(pic) {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('list');
|
||||
let uri = endpoint.uri.replace('{pic}', pic);
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method)
|
||||
.then( async serverData => { return this.sanitize(serverData.payload) })
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a specific coaching. Currently sending user to SMED mycoachings (id is no use right now either)
|
||||
* @param {*} id
|
||||
*/
|
||||
read(id) {
|
||||
let endpoint = this.getApiEndpoint('read');
|
||||
|
||||
window.open(endpoint.uri, '_blank');
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('ApplicantOrganisationCoachingsModel', ApplicantOrganisationCoachingsModel);
|
||||
@@ -1,43 +0,0 @@
|
||||
class ApplicantOrganisationsModel extends EICPluralModel {
|
||||
|
||||
constructor(privileges) {
|
||||
super('/organisations', privileges);
|
||||
this.singletonClass = class {
|
||||
itemData = {
|
||||
pic: null,
|
||||
legalname: null,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
search(criteria) { // search onlegalname can bring several
|
||||
if(!this.hasPrivilege('search')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('search');
|
||||
let uri = endpoint.uri
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, {'search': criteria })
|
||||
.then( async serverData => this.loadData(serverData.payload))
|
||||
)
|
||||
}
|
||||
|
||||
list() {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('list');
|
||||
let uri = endpoint.uri
|
||||
return (
|
||||
this.request(uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
const payload = serverData.payload;
|
||||
//this.fill(payload);
|
||||
|
||||
return payload;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
app.registerClass('ApplicantOrganisationsModel', ApplicantOrganisationsModel);
|
||||
@@ -1,51 +0,0 @@
|
||||
class BypassCompanyModel extends EICModel {
|
||||
|
||||
constructor(privileges) {
|
||||
super('company', privileges);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for a company based on its PIC and retrieves its information and the allocated token if applies
|
||||
* @param {*} endpoint
|
||||
* @param {*} payload
|
||||
* @returns
|
||||
*/
|
||||
search(pic) {
|
||||
if(!this.hasPrivilege('search')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('search');
|
||||
let uri = endpoint.uri.replace('{pic}', pic);
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method)
|
||||
.then( async serverData => this.loadData(serverData.payload))
|
||||
)
|
||||
}
|
||||
|
||||
grant(pic, payload) {
|
||||
if(!this.hasPrivilege('grant')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('grant');
|
||||
let uri = endpoint.uri.replace('{pic}', pic);
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, payload).then(
|
||||
(reply) => { // Now that we have a token, populate company model with it (was null)
|
||||
this.itemData.token = reply.payload.token
|
||||
return(reply)
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
revoke(pic, payload) {
|
||||
if(!this.hasPrivilege('revoke')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('revoke');
|
||||
let uri = endpoint.uri.replace('{pic}', pic);
|
||||
|
||||
return this.request(uri, endpoint.method, payload);
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('BypassCompanyModel', BypassCompanyModel);
|
||||
@@ -1,119 +0,0 @@
|
||||
class SoeModel extends EICModel {
|
||||
|
||||
latestProject = null;
|
||||
|
||||
constructor(privileges) {
|
||||
super('/soe', privileges);
|
||||
}
|
||||
|
||||
list() {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('list');
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
members() {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('members');
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
fundings(companyId, projectId) {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('project');
|
||||
endpoint.uri = endpoint.uri.replace('{pic}', companyId);
|
||||
endpoint.uri = endpoint.uri.replace('{projectId}', projectId);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
this.latestProject = serverData.payload;
|
||||
return this.latestProject;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
getFeedback(id) {
|
||||
return this.latestProject ? this.latestProject.fundings.find(item => item.id == id) : null;
|
||||
}
|
||||
|
||||
item(companyId, projectId, fundingId) {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('read');
|
||||
endpoint.uri = endpoint.uri.replace('{pic}', companyId);
|
||||
endpoint.uri = endpoint.uri.replace('{projectId}', projectId);
|
||||
endpoint.uri = endpoint.uri.replace('{fundingId}', fundingId);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
create(companyId, projectId, payload) {
|
||||
if(!this.hasPrivilege('create')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('create');
|
||||
endpoint.uri = endpoint.uri.replace('{pic}', companyId);
|
||||
endpoint.uri = endpoint.uri.replace('{projectId}', projectId);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, payload)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
update(companyId, projectId, fundingId, payload) {
|
||||
if(!this.hasPrivilege('update')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('update');
|
||||
endpoint.uri = endpoint.uri.replace('{pic}', companyId);
|
||||
endpoint.uri = endpoint.uri.replace('{projectId}', projectId);
|
||||
endpoint.uri = endpoint.uri.replace('{fundingId}', fundingId);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, payload)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
delete(companyId, projectId, fundingId) {
|
||||
if(!this.hasPrivilege('delete')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('delete');
|
||||
endpoint.uri = endpoint.uri.replace('{pic}', companyId);
|
||||
endpoint.uri = endpoint.uri.replace('{projectId}', projectId);
|
||||
endpoint.uri = endpoint.uri.replace('{fundingId}', fundingId);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('SoeModel', SoeModel);
|
||||
@@ -1,58 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ICMPProjectModel extends EICModel {
|
||||
|
||||
current = null;
|
||||
|
||||
constructor(privileges) { super('/icmp', privileges); }
|
||||
|
||||
get(number) {
|
||||
if(!this.hasPrivilege('read')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
this.current = null;
|
||||
|
||||
let endpoint = this.getApiEndpoint('getProject');
|
||||
endpoint.uri = endpoint.uri.replace('{projectId}', number);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
this.current = this.sanitize(serverData.payload);
|
||||
return this.current;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
sanitize(data) { return data; }
|
||||
|
||||
documents(number) {
|
||||
if(!this.hasPrivilege('read')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('getProjectDocuments');
|
||||
endpoint.uri = endpoint.uri.replace('{projectId}', number);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
contributors(number) {
|
||||
if(!this.hasPrivilege('read')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('getProjectContributors');
|
||||
endpoint.uri = endpoint.uri.replace('{projectId}', number);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('ICMPProjectModel', ICMPProjectModel);
|
||||
@@ -1,83 +0,0 @@
|
||||
class ICMPProjectNodeModel extends EICModel {
|
||||
|
||||
currentProject = null;
|
||||
|
||||
constructor(privileges) { super('/icmp', privileges); }
|
||||
|
||||
get(number, node, nodeId) {
|
||||
if(!this.hasPrivilege('read')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('getProjectNode');
|
||||
endpoint.uri = endpoint.uri.replace('{projectId}', number);
|
||||
endpoint.uri = endpoint.uri.replace('{node}', node);
|
||||
endpoint.uri = endpoint.uri.replace('{nodeId}', nodeId);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
process(action, number, node, nodeId, payload) {
|
||||
switch (action) {
|
||||
case 'saving':
|
||||
if(!this.hasPrivilege('update')) return( new Promise((resolve, reject) => reject()))
|
||||
break;
|
||||
case 'submitting':
|
||||
if(!this.hasPrivilege('submit')) return( new Promise((resolve, reject) => reject()))
|
||||
break;
|
||||
case 'validating':
|
||||
if(!this.hasPrivilege('validate')) return( new Promise((resolve, reject) => reject()))
|
||||
break;
|
||||
case 'aborting':
|
||||
if(!this.hasPrivilege('cancel')) return( new Promise((resolve, reject) => reject()))
|
||||
break;
|
||||
case 'reviewing':
|
||||
if(!this.hasPrivilege('sendforreview')) return( new Promise((resolve, reject) => reject()))
|
||||
break;
|
||||
}
|
||||
|
||||
let endpoint = this.getApiEndpoint('saveProjectNode');
|
||||
endpoint.uri = endpoint.uri.replace('{projectId}', number);
|
||||
endpoint.uri = endpoint.uri.replace('{node}', node);
|
||||
endpoint.uri = endpoint.uri.replace('{nodeId}', nodeId);
|
||||
|
||||
payload.status = action;
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, payload)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
comment(action, number, node, nodeId, payload) {
|
||||
switch (action) {
|
||||
case 'rejecting':
|
||||
if(!this.hasPrivilege('reject')) return( new Promise((resolve, reject) => reject()))
|
||||
break;
|
||||
case 'reviewing':
|
||||
if(!this.hasPrivilege('review')) return( new Promise((resolve, reject) => reject()))
|
||||
break;
|
||||
}
|
||||
|
||||
let endpoint = this.getApiEndpoint('saveProjectNodeComments');
|
||||
endpoint.uri = endpoint.uri.replace('{projectId}', number);
|
||||
endpoint.uri = endpoint.uri.replace('{node}', node);
|
||||
endpoint.uri = endpoint.uri.replace('{nodeId}', nodeId);
|
||||
|
||||
payload.status = action;
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, payload)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('ICMPProjectNodeModel', ICMPProjectNodeModel);
|
||||
@@ -1,33 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ICMPProjectsModel extends EICModel {
|
||||
|
||||
list = [];
|
||||
|
||||
constructor(privileges) { super('/icmp', privileges); }
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} node
|
||||
*/
|
||||
get(phase) {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
this.list = [];
|
||||
let payload = {}
|
||||
let endpoint = this.getApiEndpoint('list');
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, payload)
|
||||
.then( async serverData => {
|
||||
this.list = this.sanitize(serverData.payload);
|
||||
return this.list;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
sanitize(data) { return data; }
|
||||
}
|
||||
|
||||
app.registerClass('ICMPProjectsModel', ICMPProjectsModel);
|
||||
@@ -1,103 +0,0 @@
|
||||
class ProjectFundingModel extends EICModel {
|
||||
|
||||
currentProject = null;
|
||||
projects = [];
|
||||
|
||||
constructor(privileges) {
|
||||
super('/icmp', privileges);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} node
|
||||
*/
|
||||
getProjects(phase) {
|
||||
|
||||
this.projects = [];
|
||||
|
||||
let payload = {}
|
||||
//if(phase) payload.phase = phase
|
||||
|
||||
/*
|
||||
this.projects = [
|
||||
{
|
||||
number: '987654321',
|
||||
acronym: 'MAXIBROUZOUF',
|
||||
status: '...'
|
||||
},
|
||||
{
|
||||
number: '965432187',
|
||||
acronym: 'Total Pepet 2000',
|
||||
status: '...'
|
||||
}
|
||||
];
|
||||
|
||||
return Promise.resolve(this.projects);
|
||||
*/
|
||||
let endpoint = this.getApiEndpoint('list');
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, payload)
|
||||
.then( async serverData => {
|
||||
this.projects = this.sanitizeProjects(serverData.payload);
|
||||
return this.projects;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
sanitizeProjects(data) { return data; }
|
||||
|
||||
getProject(number) {
|
||||
//if(!this.hasPrivilege('getProject')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
this.currentProject = null;
|
||||
|
||||
let endpoint = this.getApiEndpoint('getProject');
|
||||
endpoint.uri = endpoint.uri.replace('{projectId}', number);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
this.currentProject = this.sanitizeProject(serverData.payload);
|
||||
return this.currentProject;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
sanitizeProject(data) { return data; }
|
||||
|
||||
getProjectNode(number, node, nodeId) {
|
||||
//if(!this.hasPrivilege('update')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('getProjectNode');
|
||||
endpoint.uri = endpoint.uri.replace('{projectId}', number);
|
||||
endpoint.uri = endpoint.uri.replace('{node}', node);
|
||||
endpoint.uri = endpoint.uri.replace('{nodeId}', nodeId);
|
||||
console.log(endpoint)
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
updateProjectNode(number, node, nodeId, payload) {
|
||||
//if(!this.hasPrivilege('update')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('saveProjectNode');
|
||||
endpoint.uri = endpoint.uri.replace('{projectId}', number);
|
||||
endpoint.uri = endpoint.uri.replace('{node}', node);
|
||||
endpoint.uri = endpoint.uri.replace('{nodeId}', nodeId);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, payload)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
app.registerClass('ProjectFundingModel', ProjectFundingModel);
|
||||
@@ -1,336 +0,0 @@
|
||||
class SubmissionModel extends EICModel {
|
||||
|
||||
constructor(privileges) {
|
||||
super('/organisations/{pic}/proposals/{pid}', privileges);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes legacy short proposals form format
|
||||
* @param {*} item
|
||||
* @returns
|
||||
*/
|
||||
sanitizeLegacy(item) {
|
||||
|
||||
let merged = {...item.DiagnosticSubmission, ...item.Diagnostic};
|
||||
this.data = item;
|
||||
this.data.team = JSON.parse(JSON.stringify(item.DiagnosticTeamMembers));
|
||||
this.data.UpdatedAt = item.DiagnosticSubmission.UpdatedAt;
|
||||
this.data.resubmitted = item.DiagnosticSubmission.ResubmissionType ? true: false;
|
||||
|
||||
delete this.data.DiagnosticSubmission;
|
||||
delete this.data.Diagnostic;
|
||||
|
||||
for(let key in merged) {
|
||||
this.data[key] = merged[key];
|
||||
}
|
||||
|
||||
return this.sanitize(this.data);
|
||||
}
|
||||
|
||||
sanitize(item) {
|
||||
if(['created', 'updated'].includes(item.status)) item.status = 'draft';
|
||||
if(['evaluation-finalised'].includes(item.status)) item.status = 'evaluated';
|
||||
if(['evaluation-contested'].includes(item.status)) item.status = 'contested';
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
getProposalLegacy(pic, number) {
|
||||
//if(!this.hasPrivilege('read')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('read');
|
||||
endpoint.uri = endpoint.uri.replace('{pic}', pic);
|
||||
endpoint.uri = endpoint.uri.replace('{pid}', number);
|
||||
/**/
|
||||
|
||||
return (
|
||||
this.request('https://api.dev.eismea.eu/stable/bypass/legacy/short-proposals'+'?'+crypto.randomUUID(), 'POST', { params: { ProposalId: number}})
|
||||
.then( async serverData => {
|
||||
return this.sanitizeLegacy(serverData.payload);
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
getProposal(pic, number) {
|
||||
if(!this.hasPrivilege('read')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('read');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{pid}', number);
|
||||
|
||||
return (
|
||||
this.request(uri+'?'+crypto.randomUUID(), endpoint.method)
|
||||
.then( async serverData => {
|
||||
switch(serverData.payload.version) {
|
||||
case '1.1':
|
||||
case '1.0':
|
||||
this.data = serverData.payload;
|
||||
return this.sanitize(this.data);
|
||||
default:
|
||||
return this.sanitizeLegacy(serverData.payload);
|
||||
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches latest company info from F&T portal
|
||||
* @param {string} pic
|
||||
* @returns
|
||||
*/
|
||||
getOrganisationInfo(pic) {
|
||||
if(!this.hasPrivilege('update')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('organisationUpdate');
|
||||
let uri = endpoint.uri.replace('{pic}', pic);
|
||||
|
||||
return (
|
||||
this.request(uri+'?'+crypto.randomUUID(), endpoint.method)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves proposal form
|
||||
* @param {*} number
|
||||
* @param {*} payload
|
||||
* @returns
|
||||
*/
|
||||
save(pic, number, form) {
|
||||
if(!this.hasPrivilege('update')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('update');
|
||||
endpoint.uri = endpoint.uri.replace('{pic}', pic);
|
||||
endpoint.uri = endpoint.uri.replace('{pid}', number);
|
||||
|
||||
let payload = {
|
||||
status: 'draft',
|
||||
form: form
|
||||
}
|
||||
|
||||
//this.merge(this.data, form);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri+'?'+crypto.randomUUID(), endpoint.method, payload)
|
||||
.then( async serverData => { return serverData.payload; })
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits the short proposal
|
||||
* @param {*} number
|
||||
* @param {*} payload
|
||||
*/
|
||||
submit(pic,number, form) {
|
||||
if(!this.hasPrivilege('update')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('update');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{pid}', number);
|
||||
|
||||
let payload = {
|
||||
status: 'submitting',
|
||||
form: form
|
||||
}
|
||||
|
||||
return (
|
||||
this.request(uri+'?'+crypto.randomUUID(), endpoint.method, payload)
|
||||
.then( async serverData => { return serverData.payload; })
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Withdraws the submitted short proposal
|
||||
* @param {*} number
|
||||
* @param {*} payload
|
||||
*/
|
||||
withdraw(pic,number, form) {
|
||||
if(!this.hasPrivilege('withdraw')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('update');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{pid}', number);
|
||||
|
||||
let payload = {
|
||||
status: 'withdrawing',
|
||||
form: form
|
||||
}
|
||||
|
||||
return (
|
||||
this.request(uri+'?'+crypto.randomUUID(), endpoint.method, payload)
|
||||
.then( async serverData => { return serverData.payload; })
|
||||
)
|
||||
}
|
||||
|
||||
clone(pic, number) {
|
||||
if(!this.hasPrivilege('clone')) return ( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('clone');
|
||||
let uri = endpoint.uri.replace('{pic}', pic);
|
||||
|
||||
let payload = {
|
||||
sourceProposal: number
|
||||
}
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, payload)
|
||||
.then( async serverData => { return serverData.payload })
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Complains the evaluation of the short proposal
|
||||
* @param {*} number
|
||||
* @param {*} payload
|
||||
*/
|
||||
complain(pic,number, form) {
|
||||
if(!this.hasPrivilege('complain')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('complain');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{pid}', number);
|
||||
|
||||
/*
|
||||
let payload = {
|
||||
status: 'complaining',
|
||||
form: form
|
||||
}
|
||||
*/
|
||||
return (
|
||||
this.request(uri+'?'+crypto.randomUUID(), endpoint.method, form)
|
||||
.then( async serverData => { return serverData.payload; })
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('SubmissionModel', SubmissionModel);
|
||||
|
||||
class SubmissionTeamModel extends EICModel {
|
||||
|
||||
constructor(privileges) {
|
||||
super('/organisations/{pic}/proposals/{pid}/team', privileges);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a team member to the short proposal
|
||||
* @param {*} member
|
||||
* @returns
|
||||
*/
|
||||
create(pic, number, member) {
|
||||
if(!this.hasPrivilege('create')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('create');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{pid}', number);
|
||||
|
||||
return (
|
||||
this.request(uri+'?'+crypto.randomUUID(), endpoint.method, member)
|
||||
.then( async serverData => { return serverData.payload; })
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a team member of the short proposal
|
||||
* @param {*} member
|
||||
* @returns
|
||||
*/
|
||||
update(pic, number, member) {
|
||||
if(!this.hasPrivilege('update')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('update');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{pid}', number).replace('{uid}', member.id);
|
||||
|
||||
return (
|
||||
this.request(uri+'?'+crypto.randomUUID(), endpoint.method, member)
|
||||
.then( async serverData => { return serverData.payload; })
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a team member from the short proposal
|
||||
* @param {*} id
|
||||
* @returns
|
||||
*/
|
||||
delete(pic, number, id) {
|
||||
if(!this.hasPrivilege('delete')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('delete');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{pid}', number).replace('{uid}', id);
|
||||
|
||||
return (
|
||||
this.request(uri+'?'+crypto.randomUUID(), endpoint.method)
|
||||
.then( async serverData => { return serverData.payload; })
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('SubmissionTeamModel', SubmissionTeamModel);
|
||||
|
||||
class SubmissionMembersModel extends EICModel {
|
||||
contributors = [];
|
||||
|
||||
constructor(privileges) {
|
||||
super('/organisations/{pic}/proposals/{pid}/members', privileges);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the contributors list on a proposal
|
||||
* @param {string} pic
|
||||
* @param {string} pid
|
||||
* @returns
|
||||
*/
|
||||
list(pic,pid) {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('list');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{pid}', pid);
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
this.contributors = serverData.payload;
|
||||
return this.contributors;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Grants to an organisation member access to the short proposal
|
||||
* @param {string} pic
|
||||
* @param {string} pid
|
||||
* @param {string} uid
|
||||
* @returns
|
||||
*/
|
||||
grant(pic, pid, uid) {
|
||||
if(!this.hasPrivilege('grant')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('grant');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{pid}', pid).replace('{uid}', uid);
|
||||
let proposalLink = '/organisations/{pic}/proposals/{pid}'.replace('{pic}',pic).replace('{pid}',pid)
|
||||
return (
|
||||
this.request(uri, endpoint.method, { status: 'active', proposalLink: proposalLink})
|
||||
.then( async serverData => { return serverData.payload })
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Revokes an organisation member access to the short proposal
|
||||
* @param {string} pic
|
||||
* @param {string} pid
|
||||
* @param {string} uid
|
||||
* @returns
|
||||
*/
|
||||
revoke(pic, pid, uid) {
|
||||
if(!this.hasPrivilege('revoke')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('revoke');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{pid}', pid).replace('{uid}', uid);
|
||||
let proposalLink = '/organisations/{pic}/proposals/{pid}'.replace('{pic}',pic).replace('{pid}',pid)
|
||||
return (
|
||||
this.request(uri, endpoint.method, { status: 'deleted', proposalLink: proposalLink })
|
||||
.then( async serverData => { return serverData.payload })
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
app.registerClass('SubmissionMembersModel', SubmissionMembersModel);
|
||||
@@ -1,184 +0,0 @@
|
||||
class MarklogicModel extends EICModel {
|
||||
|
||||
entityTypes = [
|
||||
{
|
||||
ref: '',
|
||||
label: '(entity)',
|
||||
icon: '',
|
||||
filters: [ ]
|
||||
},
|
||||
{
|
||||
ref: 'person',
|
||||
label: 'Person',
|
||||
icon: '',
|
||||
filters: [ 'id', 'euLogin', 'email' ]
|
||||
},
|
||||
{
|
||||
ref: 'application',
|
||||
label: 'App',
|
||||
icon: '',
|
||||
filters: [ ]
|
||||
},
|
||||
{
|
||||
ref: 'evaluation',
|
||||
label: 'SP Evaluation',
|
||||
icon: '',
|
||||
filters: [ ]
|
||||
},
|
||||
{
|
||||
ref: 'organisation',
|
||||
label: 'Organisation',
|
||||
icon: '',
|
||||
filters: [ 'id', 'pic' ]
|
||||
}
|
||||
]
|
||||
|
||||
payload = {
|
||||
entities: [],
|
||||
relations: []
|
||||
};
|
||||
|
||||
constructor(privileges) {
|
||||
|
||||
super('explorer', privileges);
|
||||
|
||||
}
|
||||
|
||||
getType(type) { return this.entityTypes.find(item => item.ref == type) || this.entityTypes.find(item => item.ref == ''); }
|
||||
|
||||
filters() {
|
||||
//if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('filters');
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
search(filters) {
|
||||
//if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('search');
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, filters)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('MarklogicModel', MarklogicModel);
|
||||
|
||||
/* Leftovers
|
||||
|
||||
addPerson() {
|
||||
let fnames = ['Mike', 'Marc', 'Nico', 'John', 'Jack', 'Sam', 'Steve', 'Mary', 'July']
|
||||
let lnames = ['Myers', 'Vandenbroek', 'Dumoulin', 'Smith', 'Yamaha', 'Roland', 'Jones', 'Flintstone', 'Moog']
|
||||
|
||||
let fname = fnames[Math.floor(Math.random() * fnames.length)]
|
||||
let lname = lnames[Math.floor(Math.random() * lnames.length)]
|
||||
let item = {
|
||||
id: crypto.randomUUID().substring(0,8),
|
||||
label: fname + ' ' + lname,
|
||||
type: 'person',
|
||||
userProfile: {
|
||||
euLogin: lname.substring(0,5).toLowerCase() + fname.substring(0,2).toLowerCase(),
|
||||
roles: [
|
||||
{
|
||||
role: [
|
||||
{
|
||||
referenceItemKey: {
|
||||
key: "dK1kTbD_kSAS64tAxGB4LoQ",
|
||||
_value: "ByPass Project Officer"
|
||||
}
|
||||
},
|
||||
{
|
||||
referenceItemKey: {
|
||||
key: "dlcsLwB2vQMOPEXN5D8PUQg",
|
||||
_value: "EIC Developer"
|
||||
}
|
||||
},
|
||||
{
|
||||
referenceItemKey: {
|
||||
key: "d3XJP_8OETQyb4Qqmip2ypw",
|
||||
_value: "EIC_Admin"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
information: {
|
||||
gender: {
|
||||
referenceItemKey: {
|
||||
key: "dKQGjloGhSbGlOKIiABV8eQ",
|
||||
_value: "M"
|
||||
}
|
||||
},
|
||||
name: {
|
||||
firstName: fname,
|
||||
lastName: lname
|
||||
},
|
||||
contacts: {
|
||||
email: fname + '.' + lname + '@someemail.com',
|
||||
phone: '+324' + Math.random().toString().slice(2,8)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
this.payload.entities.push(item);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
addOrg() {
|
||||
let fnames = ['co', 'glass', 'alu', 'art', 'steel', 'eco', 'son', 'digit', 'net', 'tech', 'bio', 'nano', 'tron']
|
||||
let lnames = ['sprl', 'ltd', 'inc.', 'gmbh', 'intl.', 'sa']
|
||||
|
||||
let name = fnames[Math.floor(Math.random() * fnames.length)] + fnames[Math.floor(Math.random() * fnames.length)] + ' ' + lnames[Math.floor(Math.random() * lnames.length)]
|
||||
|
||||
let item = {
|
||||
id: crypto.randomUUID().substring(0,8),
|
||||
label: name,
|
||||
type: 'organisation',
|
||||
information: {
|
||||
pic: '8' + Math.random().toString().slice(2,8),
|
||||
legalName: name
|
||||
},
|
||||
statusHistory: [
|
||||
{
|
||||
status: {
|
||||
value: "created",
|
||||
dateTime: "2023-07-18T15:27:06.397381Z",
|
||||
changedByKey: "d4rP8zgrURMiAAv-StY9YKQ"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
this.payload.entities.push(item);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
addLink(org, person) {
|
||||
if(!this.payload.relations.find(
|
||||
item => (item.source == org.id && item.target == person.id) || (item.target == org.id && item.source == person.id))) {
|
||||
let relation = {
|
||||
source: org.id,
|
||||
target: person.id
|
||||
}
|
||||
|
||||
this.payload.relations.push(relation)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
@@ -1,176 +0,0 @@
|
||||
class PlatformModel extends EICBusModel {
|
||||
|
||||
getUsers() {
|
||||
return(
|
||||
this.busWssGwRequest('GETACTIVEUSERS')
|
||||
.then(
|
||||
list => {
|
||||
if(!list) list = []
|
||||
list.sort((a,b) => {
|
||||
if(a.family_name<b.family_name) return(-1)
|
||||
else if(a.family_name>b.family_name) return(1)
|
||||
else if(a.given_name<b.given_name) return(-1)
|
||||
else return(1)
|
||||
})
|
||||
return(list)
|
||||
},
|
||||
() => [] // Empty list on connection timeout
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
getPlatformStatus() {
|
||||
return(
|
||||
this.busWssGwRequest('GETPLATFORMMODE', {}).then(data=>{
|
||||
if(!data) return(null)
|
||||
if(data.platformRestrictions) data.platformRestrictions.allowedUUIDs = data.platformRestrictions.allowedUUIDs || []
|
||||
data.blockedUUIDs = data.blockedUUIDs || []
|
||||
return(data)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
setPlatformStatus(status){
|
||||
app.MessageBus.requestWssGwAction('SETPLATFORMMODE', status)
|
||||
}
|
||||
|
||||
async getDaemonsStatus(){
|
||||
let daemons = {
|
||||
wssGateway:false,
|
||||
httpGateway:false,
|
||||
midas:false
|
||||
}
|
||||
for(let daemon of Object.keys(daemons)){
|
||||
let result = null
|
||||
if(daemon == 'wssGateway'){ //for him, ask direct in wss
|
||||
result = await app.MessageBus.requestWssGwAction('TIME',{}, 200)
|
||||
} else { //all the others we talk via bus
|
||||
try{
|
||||
result = await this.busActionRequest(`infraNotifs:${daemon}`, 'TIME', {}, 200)
|
||||
} catch(err) {
|
||||
console.warn(`Daemon ${daemon} timed out on TIME request ! `)
|
||||
}
|
||||
|
||||
}
|
||||
daemons[daemon] = (result !== null) ? result[`${daemon}Time`] : false
|
||||
}
|
||||
return(daemons)
|
||||
}
|
||||
|
||||
async ban(uid) {
|
||||
let status = await this.getPlatformStatus()
|
||||
if(!status.blockedUUIDs.includes(uid)) status.blockedUUIDs.push(uid)
|
||||
this.setPlatformStatus(status)
|
||||
this.kick(uid)
|
||||
}
|
||||
|
||||
async unban(uid) {
|
||||
let status = await this.getPlatformStatus()
|
||||
let idx = status.blockedUUIDs.indexOf(uid)
|
||||
if(idx>-1) status.blockedUUIDs.splice(idx,1)
|
||||
this.setPlatformStatus(status)
|
||||
}
|
||||
|
||||
async stopPlatform(data){
|
||||
let status = await this.getPlatformStatus()
|
||||
if(status.XX_platformRestrictions) delete(status.XX_platformRestrictions)
|
||||
status.platformRestrictions = {
|
||||
"allowedRoles": data.allowedRoles,
|
||||
"allowedUUIDs": data.allowedUUIDs,
|
||||
}
|
||||
this.setPlatformStatus(status)
|
||||
}
|
||||
|
||||
async startPlatform(data){
|
||||
let status = await this.getPlatformStatus()
|
||||
this.setPlatformStatus({
|
||||
"blockedUUIDs":status.blockedUUIDs
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
growlOne(uid, growlData) {
|
||||
let userNotifChan = app.config.messageBus.userNotifChan.replace(/\{uid\}/g, uid)
|
||||
growlData.growlMessage = growlData.growlMessage.replace(/\n/g,'<br>')
|
||||
this.busEvent(userNotifChan, 'growl', growlData)
|
||||
}
|
||||
|
||||
growlGlobal(growlData) {
|
||||
growlData.growlMessage = growlData.growlMessage.replace(/\n/g,'<br>')
|
||||
this.busEvent('system:notifs', 'growl', growlData)
|
||||
}
|
||||
|
||||
kick(uid) {
|
||||
let userNotifChan = app.config.messageBus.userNotifChan.replace(/\{uid\}/g, uid)
|
||||
this.busEvent(userNotifChan, 'kick')
|
||||
return(
|
||||
this.busWssGwRequest('KILLSESSION', {
|
||||
uids: [ uid ],
|
||||
notRoles : ['EIC_admin', 'EIC_Dev' ],
|
||||
ttl: 0
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
kickAll() {
|
||||
this.busEvent('system:notifs', 'kick')
|
||||
return(
|
||||
this.busWssGwRequest('KILLSESSION', {
|
||||
uids: null,
|
||||
notRoles : ['EIC_admin', 'EIC_Dev' ],
|
||||
ttl: 0
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
refreshWssGwRights(){
|
||||
return(
|
||||
this.busWssGwRequest('RELOADACCESSRIGHTS', {})
|
||||
)
|
||||
}
|
||||
|
||||
viewWssGwRights(){
|
||||
return(
|
||||
this.busWssGwRequest('GETACCESSRIGHTS', {})
|
||||
)
|
||||
}
|
||||
|
||||
refreshHttpGwRights(){
|
||||
return(
|
||||
this.busActionRequest('infraNotifs:httpGateway', 'RELOADACCESSRIGHTS', {})
|
||||
)
|
||||
}
|
||||
|
||||
viewHttpGwRights(){
|
||||
return(
|
||||
this.busActionRequest('infraNotifs:httpGateway', 'GETACCESSRIGHTS', {})
|
||||
)
|
||||
}
|
||||
|
||||
refreshMidasConfig(){
|
||||
return(
|
||||
this.busActionRequest('infraNotifs:midas', 'RELOADCONFIG', {})
|
||||
)
|
||||
}
|
||||
|
||||
viewMidasConfig(){
|
||||
return(
|
||||
this.busActionRequest('infraNotifs:midas', 'GETCONFIG', {})
|
||||
)
|
||||
}
|
||||
|
||||
refreshMidasPlugins(){
|
||||
return(
|
||||
this.busActionRequest('infraNotifs:midas', 'RELOADPLUGINS', {})
|
||||
)
|
||||
}
|
||||
|
||||
viewMidasPlugins(){
|
||||
return(
|
||||
this.busActionRequest('infraNotifs:midas', 'LISTPLUGINS', {})
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
app.registerClass('PlatformModel', PlatformModel);
|
||||
@@ -1,87 +0,0 @@
|
||||
class SupportModel extends EICModel {
|
||||
|
||||
constructor(privileges) {
|
||||
super('/zammad/tickets', privileges);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
list(filters) {
|
||||
//if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('list');
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, filters)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
get(id) {
|
||||
// if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('get');
|
||||
endpoint.uri = endpoint.uri.replace('{id}', id);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
create(ticket) {
|
||||
//if(!this.hasPrivilege('create')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('create');
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, ticket)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
update(id, content) {
|
||||
//if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('update');
|
||||
endpoint.uri = endpoint.uri.replace('{id}', id);
|
||||
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, content)
|
||||
.then( async serverData => {
|
||||
return serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
download(ticketId, articleId, attachmentId) {
|
||||
// if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('download');
|
||||
endpoint.uri = endpoint.uri.replace('{ticid}', ticketId);
|
||||
endpoint.uri = endpoint.uri.replace('{artid}', articleId);
|
||||
endpoint.uri = endpoint.uri.replace('{attid}', attachmentId);
|
||||
|
||||
window.open(endpoint.uri, '_blank');
|
||||
}
|
||||
}
|
||||
app.registerClass('SupportModel', SupportModel);
|
||||
@@ -1,110 +0,0 @@
|
||||
class BypassUsersModel extends EICPluralModel {
|
||||
|
||||
constructor(privileges) {
|
||||
|
||||
super('users', privileges);
|
||||
|
||||
this.singletonClass = class {
|
||||
itemData = {
|
||||
uuid: null,
|
||||
firstname: null,
|
||||
lastname: null,
|
||||
role: null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getUid(uid) {
|
||||
return(this.collection.find(x=>(x.uid == uid)));
|
||||
}
|
||||
|
||||
create(payload) {
|
||||
if(!this.hasPrivilege('create')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('create');
|
||||
return ( this.request(endpoint.uri, endpoint.method, payload) );
|
||||
}
|
||||
|
||||
revoke(uid) {
|
||||
if(!this.hasPrivilege('revoke')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('revoke');
|
||||
let uri = endpoint.uri.replace('{id}', uid);
|
||||
|
||||
return this.request(uri, endpoint.method, null);
|
||||
}
|
||||
|
||||
search(hint) {
|
||||
// This is publicly avail, don't check until ML understand what anonymous means
|
||||
// if(!this.hasPrivilege('search')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('search');
|
||||
let uri = endpoint.uri.replace('{id}', hint);
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, {'hint': hint })
|
||||
.then( async serverData => {
|
||||
let users = serverData.payload.map(x=> { // Cleanup keys starting with https://
|
||||
for(let k in x){
|
||||
if(k.substring(0,4)=='http') { x[k.substring(k.lastIndexOf('/')+1)]=x[k]; delete(x[k]);}
|
||||
} return(x);
|
||||
} )
|
||||
return(users);
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
sanitize(item) {
|
||||
//TODO what if several BP_ roles...
|
||||
item.BProle = item.roles.filter(r => (r.substring(0,3)=='BP_'))[0];
|
||||
let trackTree = null;
|
||||
if(item.track) {
|
||||
trackTree = app.meta.getItem('accelerator-tracks',item.track);
|
||||
item.track = { id: item.track, label: trackTree.label };
|
||||
} else {
|
||||
item.track = { id: null, label: '(n/a)' };
|
||||
}
|
||||
|
||||
if((item.domain) && (trackTree)){
|
||||
item.domain = { id: item.domain, label: app.meta.getItemRecurse(trackTree, item.domain).label };
|
||||
} else {
|
||||
item.domain = { id: null, label: '(n/a)' };
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
list(filters) {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('list');
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, filters)
|
||||
.then( async serverData => {
|
||||
const payload = serverData.payload;
|
||||
this.fill(payload);
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
// Not sure why / when / where they think I'll need it, but it exists (and takes 2.5 seconds to get 5 strings)
|
||||
// If someday the response-time is decent, and if we have the delegationRules the payload...maybe...
|
||||
getRoles() {
|
||||
if(!this.hasPrivilege('getRoles')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = app.config.api.roles.list;
|
||||
return (
|
||||
this.request(endpoint.uri, endpoint.method, {})
|
||||
.then( async serverData => {
|
||||
this.existingRoles = serverData.payload;
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
fill(serverData) {
|
||||
if(serverData && serverData.length) {
|
||||
this.collection = [];
|
||||
for(let singletonData of serverData) this.collection.push(this.sanitize(singletonData));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('BypassUsersModel', BypassUsersModel);
|
||||
@@ -1,85 +0,0 @@
|
||||
class applicantModel extends EICModel {
|
||||
|
||||
constructor(privileges) {
|
||||
super('applicant', privileges);
|
||||
}
|
||||
|
||||
getOrganisations() {
|
||||
let responsePayload = [
|
||||
{
|
||||
pic: 12345678,
|
||||
legalname: 'NightShift.be SNC'
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve(responsePayload);
|
||||
}, 300);
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
getOrganisationSummary(pic) {
|
||||
let responsePayload = {
|
||||
pic: 12345678,
|
||||
legalname: 'NightShift.be SNC',
|
||||
proposals: [
|
||||
{
|
||||
id: 14373,
|
||||
proposalNumber: '190129445',
|
||||
acronym: 'patchd',
|
||||
status: 'draft',
|
||||
type: 'short',
|
||||
accessRequests: 2,
|
||||
version: 'legacy1.0'
|
||||
},
|
||||
{
|
||||
id: 99999,
|
||||
proposalNumber: '999123456',
|
||||
acronym: 'fastinfra',
|
||||
status: 'draft',
|
||||
type: 'short',
|
||||
accessRequests: 2,
|
||||
version: '2023'
|
||||
}
|
||||
],
|
||||
coachings: [],
|
||||
members: [
|
||||
{
|
||||
uid: 'fallimi',
|
||||
firstname: 'Michael',
|
||||
lastname: 'Fallise',
|
||||
function: 'Chief Executive Officer',
|
||||
status: 'active'
|
||||
},
|
||||
{
|
||||
uid: 'steinni',
|
||||
firstname: 'Nicolas',
|
||||
lastname: 'Stein',
|
||||
function: 'Chief Technical Officer',
|
||||
status: 'active'
|
||||
},
|
||||
{
|
||||
uid: 'schwemi',
|
||||
firstname: 'Michael',
|
||||
lastname: 'Schweda',
|
||||
function: 'Marketing manager',
|
||||
status: 'pending'
|
||||
}
|
||||
],
|
||||
calendar: []
|
||||
};
|
||||
|
||||
return (
|
||||
new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve(responsePayload);
|
||||
}, 300);
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('applicantModel', applicantModel);
|
||||
@@ -1,120 +0,0 @@
|
||||
class onboardingUserModel extends EICPluralModel {
|
||||
|
||||
constructor(privileges) {
|
||||
|
||||
super('/organisations', privileges);
|
||||
|
||||
this.singletonClass = class {
|
||||
itemData = {
|
||||
uuid: null,
|
||||
firstname: null,
|
||||
lastname: null,
|
||||
role: null,
|
||||
organisations: []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
readOrganisation(pic) {
|
||||
if(!this.hasPrivilege('read')) return( new Promise((resolve, reject) => reject()));
|
||||
|
||||
let endpoint = this.getApiEndpoint('read');
|
||||
let uri = endpoint.uri.replace('{pic}',pic)
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
this.loadData(serverData.payload)
|
||||
return(serverData.payload)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
searchOrganisation(pic) {
|
||||
// This is publicly avail, don't check until ML understand what anonymous means
|
||||
// if(!this.hasPrivilege('search')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('search');
|
||||
let uri = endpoint.uri
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, {'search': pic })
|
||||
.then( async serverData => {
|
||||
this.loadData(serverData.payload)
|
||||
return(serverData.payload)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
registerOrganisationAccess(orgData) {
|
||||
if(!this.hasPrivilege('apply')) return( new Promise((resolve, reject) => reject()));
|
||||
let endpoint = this.getApiEndpoint('apply')
|
||||
let uri = endpoint.uri.replace('{pic}',orgData.pic).replace('{uid}', app.User.identity.uuid);
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, {
|
||||
status: 'pending',
|
||||
organisationLink: '/applicant/{pic}'.replace('{pic}',orgData.pic)
|
||||
})
|
||||
.then( async serverData => {
|
||||
return(serverData.payload)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
requestOrganisationAccess(orgData) {
|
||||
if(!this.hasPrivilege('apply')) return( new Promise((resolve, reject) => reject()));
|
||||
|
||||
let endpoint = this.getApiEndpoint('apply')
|
||||
let uri = endpoint.uri.replace('{pic}',orgData.pic).replace('{uid}', app.User.identity.uuid);
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, {
|
||||
status: 'pending',
|
||||
organisationLink: '/applicant/{pic}'.replace('{pic}',orgData.pic)
|
||||
})
|
||||
.then( async serverData => {
|
||||
return(serverData.payload)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
// MFA: needed here ? handled thru dashboard
|
||||
// Nike: Yes, good place, for rel2
|
||||
acceptRegistrationAccess(uid, pic) {
|
||||
if(!this.hasPrivilege('grant')) return( new Promise((resolve, reject) => reject()));
|
||||
let endpoint = this.getApiEndpoint('grant').replace('{pic}',pic).replace('{uid}', app.User.identity.uuid);
|
||||
let uri = endpoint.uri
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, {
|
||||
status: 'pending',
|
||||
organisationLink: '/applicant/{pic}'.replace('{pic}',pic)
|
||||
} )
|
||||
.then( async serverData => {
|
||||
return(serverData.payload)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
// MFA: needed here ? handled thru dashboard
|
||||
// Nike: Yes, good place, for rel2
|
||||
denyRegistrationAccess(uid, pic) {
|
||||
if(!this.hasPrivilege('revoke')) return( new Promise((resolve, reject) => reject()));
|
||||
let endpoint = this.getApiEndpoint('revoke').replace('{pic}',pic).replace('{uid}', app.User.identity.uuid);
|
||||
let uri = endpoint.uri
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, {
|
||||
status: 'pending',
|
||||
organisationLink: '/applicant/{pic}'.replace('{pic}',pic)
|
||||
} )
|
||||
.then( async serverData => {
|
||||
return(serverData.payload)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
app.registerClass('onboardingUserModel', onboardingUserModel);
|
||||
Reference in New Issue
Block a user