-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2033: Sync worklogs from invoice entry #147
Merged
jeppekroghitk
merged 43 commits into
develop
from
feature/2033-sync-worklogs-from-invoice-entry
Aug 14, 2024
Merged
Changes from 17 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
d8e8460
Passing invoice id to invoice entry worklog form class
jeppekroghitk 40376b2
Prepared form class to recieve invoice id, and getting periodFrom and…
jeppekroghitk 4886af4
Updated changelog
jeppekroghitk 8131b98
added button to template, created stylings, js controller and got js …
jeppekroghitk 9c45c69
Added logic to worklog sync method
jeppekroghitk 17e43c1
Added styling and improved javascript handling button
jeppekroghitk 5352ac2
Updated changelog
jeppekroghitk f6f355e
Added page reload post sync success
jeppekroghitk e70d1a5
Modified page-header component to utilize upcoming action-button comp…
jeppekroghitk c4e9667
Added action button twig component
jeppekroghitk 78c7506
Added js controller for action-button and attached postrequesthandler
jeppekroghitk d4013d9
Added icons to icon twig component
jeppekroghitk 75130b8
Implemented new action button for worklog entry page header
jeppekroghitk 1d56113
Converted some inline css to tailwind and added rest to app.css
jeppekroghitk 9a3e8b8
Cleaned up
jeppekroghitk d833bbf
Final adjustments
jeppekroghitk 9e42e47
coding standards
jeppekroghitk 1bab0ba
Fixed issue where isBillable on project could not be unset
jeppekroghitk cc8592e
Fixed typo in isBillable form label, added missing translations and m…
jeppekroghitk b71e820
Added included=true to project filters by default
jeppekroghitk 2143fa1
Added initial project get method to only include included projects, i…
jeppekroghitk 6f08ea2
Changed incorrect definition of false when settings isBillable to false
jeppekroghitk f2b6a95
Updated changelog
jeppekroghitk 3afdcc0
Passing periodFrom and periodTo to filtertype instead of invoiceid to…
jeppekroghitk 8ece8c7
Set default value to projectFilterData instead of settings it alterna…
jeppekroghitk 3c086ab
coding standards
jeppekroghitk c8176d2
Passing invoice id to invoice entry worklog form class
jeppekroghitk 07bb10b
Prepared form class to recieve invoice id, and getting periodFrom and…
jeppekroghitk d46cd1e
Updated changelog
jeppekroghitk 084d9da
Revert "Prepared form class to recieve invoice id, and getting period…
jeppekroghitk db278dd
Revert "Updated changelog"
jeppekroghitk a317150
Reapply "Prepared form class to recieve invoice id, and getting perio…
jeppekroghitk 1308016
Restored mistakenly overwritten force push
jeppekroghitk 8e85780
Removed unused variable definition and constructor
jeppekroghitk d750df2
Added type link to existing headers with link button
jeppekroghitk 2283422
Reapplied translation to worklog sync button
jeppekroghitk bcbde8c
Merge branch 'feature/2034-invoice-date-select-continuity' into featu…
jeppekroghitk 0a3a998
Coding standards
jeppekroghitk 723e2bf
Merge branch 'feature/2034-invoice-date-select-continuity' into featu…
jeppekroghitk ae75492
Restored original headline to Invoice worklog entry
jeppekroghitk a0daf44
Improved invoice worklog entry bottom sticky button bar
jeppekroghitk 1c047cc
Throwing error on management-report when no invoice is found
jeppekroghitk f4e75ef
Fixed issue regarding translations for workload report
jeppekroghitk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,88 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
import { postRequestHandler } from "../helpers/postRequestHandler"; | ||
|
||
const states = { | ||
default: "default", | ||
loading: "loading", | ||
success: "success", | ||
error: "error" | ||
}; | ||
|
||
export default class extends Controller { | ||
|
||
static targets = ["actionDefault", "actionLoading", "actionSuccess", "actionError"]; | ||
|
||
action(e) { | ||
const targets = { | ||
default: this.actionDefaultTarget, | ||
loading: this.actionLoadingTarget, | ||
success: this.actionSuccessTarget, | ||
error: this.actionErrorTarget, | ||
parent: e.target, | ||
}; | ||
const data = e.target.dataset; | ||
const url = data.url; | ||
const reload = data.reload; | ||
|
||
triggerState(states.loading, targets); | ||
postRequestHandler(url) | ||
.then(result => { | ||
if (result.success) { | ||
triggerState(states.success, targets); | ||
setTimeout(()=>{ | ||
reload && window.location.reload(); | ||
triggerState(states.default, targets); | ||
}, 2000) | ||
} else { | ||
triggerState(states.error, targets); | ||
alert(result.error); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Applies a state to the provided targets based on the given state value. | ||
* | ||
* @param {string} state - The state value to apply. | ||
* @param {object} targets - The targets to apply the state to. | ||
*/ | ||
function triggerState(state, targets) { | ||
resetState(targets); | ||
|
||
switch (state) { | ||
case states.default: | ||
targets.default.classList.remove('hidden'); | ||
break; | ||
case states.loading: | ||
targets.loading.classList.remove("hidden"); | ||
break; | ||
case states.success: | ||
targets.success.classList.remove("hidden"); | ||
targets.parent.classList.add('btn-success'); | ||
break; | ||
case states.error: | ||
targets.error.classList.remove("hidden"); | ||
targets.parent.classList.add('btn-error'); | ||
break; | ||
default: | ||
console.log("State not recognized"); | ||
} | ||
} | ||
|
||
/** | ||
* Resets the state of the targets. | ||
* | ||
* @param {object} targets - The targets to reset. | ||
* @return {void} | ||
*/ | ||
function resetState(targets) | ||
{ | ||
Object.entries(targets).forEach(([type, target]) => { | ||
target.classList.remove('btn-error', 'btn-success'); | ||
if (type === "parent") { | ||
return; | ||
} | ||
target.classList.add('hidden'); | ||
}); | ||
} |
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,35 @@ | ||
export const postRequestHandler = async (updateUrl) => { | ||
let result = { | ||
success: false, | ||
status: null, | ||
data: null, | ||
error: null | ||
}; | ||
|
||
try { | ||
const response = await fetch(updateUrl, { | ||
method: "POST", | ||
mode: "same-origin", | ||
cache: "no-cache", | ||
credentials: "same-origin", | ||
headers: { "Content-Type": "application/json" }, | ||
redirect: "follow", | ||
referrerPolicy: "no-referrer" | ||
}); | ||
|
||
result.status = response.status; | ||
|
||
if (!response.ok) { | ||
const errorData = await response.json(); | ||
throw new Error(errorData.message); | ||
} else { | ||
result.success = true; | ||
result.data = await response.json(); | ||
} | ||
} catch (error) { | ||
console.error(error.message); | ||
result.error = error.message; | ||
} | ||
|
||
return result; | ||
}; |
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
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,32 @@ | ||
{# | ||
This Twig template represents a stylized button component with different states that could be managed by a StumilusJS Controller. | ||
|
||
Parameters: | ||
- url (string, optional): | ||
An URL which can be accessed when the button is clicked. Defaults to an empty string. | ||
- reload (boolean, optional): | ||
If set to true, triggers a page reload when the button is clicked. Defaults to false. | ||
- default_text (string, optional): | ||
The default text displayed on the button. Defaults to 'default'. | ||
- loader_text (string, optional): | ||
The text displayed when the button is in the state of loading. Should be defined together with link_text variable. | ||
- success_text (string, optional): | ||
The text displayed when an action related to the button is successfully finished. Defaults to 'success'. | ||
- error_text (string, optional): | ||
The text displayed when an action related to the button has failed. Defaults to 'error'. | ||
#} | ||
|
||
<button class="action-button button w-48 h-16" data-url="{{ url|default("") }}" data-reload="{{ reload|default(false) }}" {{ stimulus_controller('action-button') }} {{ stimulus_action('action-button', 'action') }}> | ||
<span | ||
class="action-default pointer-events-none"{{ stimulus_target('action-button', 'actionDefault') }}> {{ default_text|default('default') }} | ||
</span> | ||
<span | ||
class="action-loading hidden pointer-events-none" {{ stimulus_target('action-button', 'actionLoading') }}> {{ loader_text is defined ? loader_text : include('components/icons.html.twig', {icon: 'spinner', class: 'w-6 h-6'}) }} | ||
</span> | ||
<span | ||
class="action-success hidden pointer-events-none" {{ stimulus_target('action-button', 'actionSuccess') }}>{{ success_text|default('success') }} | ||
</span> | ||
<span | ||
class="action-error hidden pointer-events-none" {{ stimulus_target('action-button', 'actionError') }}>{{ error_text|default('error') }} | ||
</span> | ||
</button> |
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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
<header class="w-full flex justify-between items-center"> | ||
<h1 class="page-title">{{ title }}</h1> | ||
{% if link_url|default(false) %} | ||
<a class="link border border-blue-600 rounded px-3 py-2 no-underline hover:bg-blue-50" href="{{ path(link_url) }}">{{ link_text }}</a> | ||
{% if type is defined %} | ||
{% if type == 'link' %} | ||
<a class="link border border-blue-600 rounded px-3 py-2 no-underline hover:bg-blue-50" href="{{ path(link_url) }}">{{ link_text }}</a> | ||
{% endif %} | ||
{% if type == 'action' %} | ||
{% include 'components/action-button.html.twig' %} | ||
{% endif %} | ||
{% endif %} | ||
|
||
</header> |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change requires that you change the other parts that use:
components/page-header.html.twig
otherwise, they will not display the link