You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.1 KiB

  1. <script lang="ts" context="module">
  2. let lastProjectId = "";
  3. </script>
  4. <script lang="ts">
  5. import stuffLogClient from "../clients/stufflog";
  6. import Modal from "../components/Modal.svelte";
  7. import ProjectSelect from "../components/ProjectSelect.svelte";
  8. import TaskSelect from "../components/TaskSelect.svelte";
  9. import markStale from "../stores/markStale";
  10. import modalStore from "../stores/modal";
  11. export let deletion = false;
  12. export let creation = false;
  13. const md = $modalStore;
  14. let projectId = "";
  15. let taskId = "";
  16. let verb = "Add";
  17. if (md.name === "tasklink.delete") {
  18. projectId = md.project.id;
  19. taskId = md.task.id;
  20. verb = "Delete";
  21. } else if (md.name === "tasklink.add") {
  22. projectId = (md.project||{id:""}).id || lastProjectId;
  23. taskId = (md.task||{id:""}).id;
  24. } else {
  25. throw new Error(`Wrong form ${md.name}`)
  26. }
  27. let error = null;
  28. let loading = false;
  29. function onSubmit() {
  30. loading = true;
  31. error = null;
  32. if (creation) {
  33. stuffLogClient.createTaskLink(projectId, taskId).then(() => {
  34. markStale("goal", "project");
  35. modalStore.close();
  36. }).catch(err => {
  37. error = err.message ? err.message : err.toString();
  38. }).finally(() => {
  39. loading = false;
  40. lastProjectId = projectId;
  41. })
  42. } else if (deletion) {
  43. stuffLogClient.deleteTaskLink(projectId, taskId).then(() => {
  44. markStale("goal", "project");
  45. modalStore.close();
  46. }).catch(err => {
  47. error = err.message ? err.message : err.toString();
  48. }).finally(() => {
  49. loading = false;
  50. lastProjectId = projectId;
  51. })
  52. }
  53. }
  54. </script>
  55. <Modal show title="{verb} Link" error={error} closable on:close={modalStore.close}>
  56. <form on:submit|preventDefault={onSubmit}>
  57. <label for="taskId">Source Task</label>
  58. <TaskSelect disabled={deletion} name="taskId" bind:value={taskId} />
  59. <label for="projectId">Destination Project</label>
  60. <ProjectSelect disabled={deletion} name="projectId" bind:value={projectId} />
  61. <hr />
  62. <button disabled={loading} type="submit">{verb} Link</button>
  63. </form>
  64. </Modal>