-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OP#41289] list all linked workpackages (#71)
Signed-off-by: Artur Neumann <artur@jankaritech.com>
- Loading branch information
1 parent
5a3a629
commit 7c85e8f
Showing
6 changed files
with
472 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { generateUrl } from '@nextcloud/router' | ||
import axios from '@nextcloud/axios' | ||
|
||
export const workpackageHelper = { | ||
async getColorAttributes(path, id) { | ||
const url = generateUrl(path + id) | ||
let response | ||
try { | ||
response = await axios.get(url) | ||
} catch (e) { | ||
response = e.response | ||
} | ||
return (response.status === 200 && response.data?.color) | ||
? response.data.color | ||
: '' | ||
}, | ||
replaceHrefToGetId(href) { | ||
// this is a helper method replaces the string like this "/api/v3/types/3" to get id | ||
return href | ||
? href.replace(/.*\//, '') | ||
: null | ||
}, | ||
async getAdditionalMetaData(workPackage) { | ||
if (typeof workPackage._links.status.href !== 'string' | ||
|| workPackage._links.status.href === '' | ||
|| typeof workPackage._links.type.href !== 'string' | ||
|| workPackage._links.type.href === '' | ||
|| typeof workPackage.id !== 'number' | ||
|| typeof workPackage.subject !== 'string' | ||
|| workPackage.subject === '' | ||
|| typeof workPackage._links.project.title !== 'string' | ||
|| workPackage._links.project.title === '' | ||
|| typeof workPackage._links.status.title !== 'string' | ||
|| workPackage._links.status.title === '' | ||
|| typeof workPackage._links.type.title !== 'string' | ||
|| workPackage._links.type.title === '' | ||
) { | ||
throw new Error('missing data in workpackage object') | ||
} | ||
const statusId = this.replaceHrefToGetId(workPackage._links.status.href) | ||
const typeId = this.replaceHrefToGetId(workPackage._links.type.href) | ||
const userId = this.replaceHrefToGetId(workPackage._links.assignee.href) | ||
const userName = workPackage._links.assignee.title | ||
const avatarUrl = generateUrl('/apps/integration_openproject/avatar?') | ||
+ encodeURIComponent('userId') | ||
+ '=' + userId | ||
+ '&' + encodeURIComponent('userName') | ||
+ '=' + userName | ||
const statusColor = await this.getColorAttributes('/apps/integration_openproject/statuses/', statusId) | ||
const typeColor = await this.getColorAttributes('/apps/integration_openproject/types/', typeId) | ||
return { | ||
id: workPackage.id, | ||
subject: workPackage.subject, | ||
project: workPackage._links.project.title, | ||
statusTitle: workPackage._links.status.title, | ||
typeTitle: workPackage._links.type.title, | ||
assignee: userName, | ||
statusCol: statusColor, | ||
typeCol: typeColor, | ||
picture: avatarUrl, | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.