From 69a142e21d0e01afec0f0ff9501430b7b589752b Mon Sep 17 00:00:00 2001 From: Suchin Sapphasitthatha Date: Tue, 4 Feb 2025 09:21:37 +0000 Subject: [PATCH 01/13] add @server@ to CI for UAT, PROD --- .onedev-buildspec.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.onedev-buildspec.yml b/.onedev-buildspec.yml index aa65f53..e03294a 100644 --- a/.onedev-buildspec.yml +++ b/.onedev-buildspec.yml @@ -1,4 +1,4 @@ -version: 37 +version: 38 jobs: - name: CI for UAT steps: @@ -40,7 +40,7 @@ jobs: name: build docker image dockerfile: ./docker/Dockerfile output: !RegistryOutput - tags: hrms-git.chin.in.th/bma-hrms/hrms-user:@build_version@ hrms-git.chin.in.th/bma-hrms/hrms-user:latest + tags: '@server@/bma-hrms/hrms-user:@build_version@ @server@/bma-hrms/hrms-user:latest' condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL triggers: - !TagCreateTrigger @@ -90,7 +90,7 @@ jobs: name: build docker image dockerfile: ./docker/Dockerfile output: !RegistryOutput - tags: hrms-git.bangkok.go.th/bma-hrms/hrms-user:@build_version@ hrms-git.bangkok.go.th/bma-hrms/hrms-user:latest + tags: '@server@/bma-hrms/hrms-user:@build_version@ @server@/bma-hrms/hrms-user:latest' condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL triggers: - !TagCreateTrigger From 54699486cc622dcd6b0a360f4d23aef2ab6d49bf Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 5 Sep 2025 15:21:26 +0700 Subject: [PATCH 02/13] workflow --- .github/workflows/release.yaml | 122 +++++++++------------------------ 1 file changed, 33 insertions(+), 89 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 0a6e50d..c4746ff 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,106 +1,50 @@ -name: release -run-name: release ${{ github.actor }} +# /.forgejo/workflows/build.yml +name: Build + on: push: tags: - - "version-[0-9]+.[0-9]+.[0-9]+" + - "v[0-9]+.[0-9]+.[0-9]+" + - "v[0-9]+.[0-9]+.[0-9]+*" workflow_dispatch: + env: - REGISTRY: docker.frappet.com - IMAGE_NAME: ehr/bma-ehr-user - DEPLOY_HOST: frappet.com - COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-user + REGISTRY: ${{ vars.CONTAINER_REGISTRY }} + REGISTRY_USERNAME: ${{ vars.CONTAINER_REGISTRY_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }} + CONTAINER_IMAGE_NAME: ${{ vars.CONTAINER_REGISTRY }}/${{ vars.CONTAINER_IMAGE_OWNER }}/${{ vars.CONTAINER_IMAGE_NAME }} + IMAGE_VERSION: build jobs: - # act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=test-v6.1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd - release: + build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - # skip Set up QEMU because it fail on act and container - # Gen Version try to get version from tag or inut - - name: Set output tags - id: vars - run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT - - name: Gen Version - id: gen_ver - run: | - if [[ $GITHUB_REF == 'refs/tags/'* ]]; then - IMAGE_VER=${{ steps.vars.outputs.tag }} - else - IMAGE_VER=${{ github.event.inputs.IMAGE_VER }} - fi - if [[ $IMAGE_VER == '' ]]; then - IMAGE_VER='test-vBeta' - fi - echo '::set-output name=image_ver::'$IMAGE_VER - - name: Test Version - run: | - echo $GITHUB_REF - echo ${{ steps.gen_ver.outputs.image_ver }} + - name: Checkout repository + uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 + with: + config-inline: | + [registry."${{ env.REGISTRY }}"] + ca=["/etc/ssl/certs/ca-certificates.crt"] + - name: Tag Version + run: | + if [[ "${{ github.event_name }}" == "push" ]]; then + echo "IMAGE_VERSION=${{ github.ref_name }}" | sed 's/v//g' >> $GITHUB_ENV + else + echo "IMAGE_VERSION=${{ env.IMAGE_VERSION }}-${{ github.run_number }}" >> $GITHUB_ENV + fi - name: Login in to registry uses: docker/login-action@v2 with: - registry: ${{env.REGISTRY}} - username: ${{secrets.DOCKER_USER}} - password: ${{secrets.DOCKER_PASS}} - - name: Build and load local docker image + registry: ${{ env.REGISTRY }} + username: ${{ env.REGISTRY_USERNAME }} + password: ${{ env.REGISTRY_PASSWORD }} + - name: Build and push docker image uses: docker/build-push-action@v3 with: - context: . platforms: linux/amd64 - file: docker/Dockerfile - push: true - tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest - - - name: Reload docker compose - uses: appleboy/ssh-action@v0.1.8 - with: - host: ${{env.DEPLOY_HOST}} - username: frappet - password: ${{ secrets.SSH_PASSWORD }} - port: 10102 - script: | - cd "${{env.COMPOSE_PATH}}" - docker compose pull - docker compose up -d - echo "${{ steps.gen_ver.outputs.image_ver }}"> success - - name: Notify Discord Success - if: success() - run: | - curl -H "Content-Type: application/json" \ - -X POST \ - -d '{ - "embeds": [{ - "title": "✅ Deployment Success!", - "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`", - "color": 3066993, - "footer": { - "text": "Release Notification", - "icon_url": "https://example.com/success-icon.png" - }, - "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'" - }] - }' \ - ${{ secrets.DISCORD_WEBHOOK }} - - - name: Notify Discord Failure - if: failure() - run: | - curl -H "Content-Type: application/json" \ - -X POST \ - -d '{ - "embeds": [{ - "title": "❌ Deployment Failed!", - "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`", - "color": 15158332, - "footer": { - "text": "Release Notification", - "icon_url": "https://example.com/failure-icon.png" - }, - "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'" - }] - }' \ - ${{ secrets.DISCORD_WEBHOOK }} \ No newline at end of file + context: . + file: ./docker/Dockerfile + tags: ${{ env.CONTAINER_IMAGE_NAME }}:latest,${{ env.CONTAINER_IMAGE_NAME }}:${{ env.IMAGE_VERSION }} + push: true \ No newline at end of file From 107340bd0cd926ce450474e1e5013e0e9c57e7e8 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 5 Sep 2025 15:33:51 +0700 Subject: [PATCH 03/13] test --- .github/workflows/release.yaml | 122 ++++++++++++++++++++++++--------- 1 file changed, 89 insertions(+), 33 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c4746ff..0a6e50d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,50 +1,106 @@ -# /.forgejo/workflows/build.yml -name: Build - +name: release +run-name: release ${{ github.actor }} on: push: tags: - - "v[0-9]+.[0-9]+.[0-9]+" - - "v[0-9]+.[0-9]+.[0-9]+*" + - "version-[0-9]+.[0-9]+.[0-9]+" workflow_dispatch: - env: - REGISTRY: ${{ vars.CONTAINER_REGISTRY }} - REGISTRY_USERNAME: ${{ vars.CONTAINER_REGISTRY_USERNAME }} - REGISTRY_PASSWORD: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }} - CONTAINER_IMAGE_NAME: ${{ vars.CONTAINER_REGISTRY }}/${{ vars.CONTAINER_IMAGE_OWNER }}/${{ vars.CONTAINER_IMAGE_NAME }} - IMAGE_VERSION: build + REGISTRY: docker.frappet.com + IMAGE_NAME: ehr/bma-ehr-user + DEPLOY_HOST: frappet.com + COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-user jobs: - build: + # act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=test-v6.1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd + release: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v4 + - uses: actions/checkout@v3 + # skip Set up QEMU because it fail on act and container + # Gen Version try to get version from tag or inut + - name: Set output tags + id: vars + run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT + - name: Gen Version + id: gen_ver + run: | + if [[ $GITHUB_REF == 'refs/tags/'* ]]; then + IMAGE_VER=${{ steps.vars.outputs.tag }} + else + IMAGE_VER=${{ github.event.inputs.IMAGE_VER }} + fi + if [[ $IMAGE_VER == '' ]]; then + IMAGE_VER='test-vBeta' + fi + echo '::set-output name=image_ver::'$IMAGE_VER + - name: Test Version + run: | + echo $GITHUB_REF + echo ${{ steps.gen_ver.outputs.image_ver }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - with: - config-inline: | - [registry."${{ env.REGISTRY }}"] - ca=["/etc/ssl/certs/ca-certificates.crt"] - - name: Tag Version - run: | - if [[ "${{ github.event_name }}" == "push" ]]; then - echo "IMAGE_VERSION=${{ github.ref_name }}" | sed 's/v//g' >> $GITHUB_ENV - else - echo "IMAGE_VERSION=${{ env.IMAGE_VERSION }}-${{ github.run_number }}" >> $GITHUB_ENV - fi - name: Login in to registry uses: docker/login-action@v2 with: - registry: ${{ env.REGISTRY }} - username: ${{ env.REGISTRY_USERNAME }} - password: ${{ env.REGISTRY_PASSWORD }} - - name: Build and push docker image + registry: ${{env.REGISTRY}} + username: ${{secrets.DOCKER_USER}} + password: ${{secrets.DOCKER_PASS}} + - name: Build and load local docker image uses: docker/build-push-action@v3 with: - platforms: linux/amd64 context: . - file: ./docker/Dockerfile - tags: ${{ env.CONTAINER_IMAGE_NAME }}:latest,${{ env.CONTAINER_IMAGE_NAME }}:${{ env.IMAGE_VERSION }} - push: true \ No newline at end of file + platforms: linux/amd64 + file: docker/Dockerfile + push: true + tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest + + - name: Reload docker compose + uses: appleboy/ssh-action@v0.1.8 + with: + host: ${{env.DEPLOY_HOST}} + username: frappet + password: ${{ secrets.SSH_PASSWORD }} + port: 10102 + script: | + cd "${{env.COMPOSE_PATH}}" + docker compose pull + docker compose up -d + echo "${{ steps.gen_ver.outputs.image_ver }}"> success + - name: Notify Discord Success + if: success() + run: | + curl -H "Content-Type: application/json" \ + -X POST \ + -d '{ + "embeds": [{ + "title": "✅ Deployment Success!", + "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`", + "color": 3066993, + "footer": { + "text": "Release Notification", + "icon_url": "https://example.com/success-icon.png" + }, + "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'" + }] + }' \ + ${{ secrets.DISCORD_WEBHOOK }} + + - name: Notify Discord Failure + if: failure() + run: | + curl -H "Content-Type: application/json" \ + -X POST \ + -d '{ + "embeds": [{ + "title": "❌ Deployment Failed!", + "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`", + "color": 15158332, + "footer": { + "text": "Release Notification", + "icon_url": "https://example.com/failure-icon.png" + }, + "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'" + }] + }' \ + ${{ secrets.DISCORD_WEBHOOK }} \ No newline at end of file From d09cda6882d0b95f04977cf50cf0b2f78d886933 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 5 Sep 2025 15:38:27 +0700 Subject: [PATCH 04/13] no message --- .forgejo/workforws/build.yml | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .forgejo/workforws/build.yml diff --git a/.forgejo/workforws/build.yml b/.forgejo/workforws/build.yml new file mode 100644 index 0000000..c4746ff --- /dev/null +++ b/.forgejo/workforws/build.yml @@ -0,0 +1,50 @@ +# /.forgejo/workflows/build.yml +name: Build + +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + - "v[0-9]+.[0-9]+.[0-9]+*" + workflow_dispatch: + +env: + REGISTRY: ${{ vars.CONTAINER_REGISTRY }} + REGISTRY_USERNAME: ${{ vars.CONTAINER_REGISTRY_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }} + CONTAINER_IMAGE_NAME: ${{ vars.CONTAINER_REGISTRY }}/${{ vars.CONTAINER_IMAGE_OWNER }}/${{ vars.CONTAINER_IMAGE_NAME }} + IMAGE_VERSION: build + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + config-inline: | + [registry."${{ env.REGISTRY }}"] + ca=["/etc/ssl/certs/ca-certificates.crt"] + - name: Tag Version + run: | + if [[ "${{ github.event_name }}" == "push" ]]; then + echo "IMAGE_VERSION=${{ github.ref_name }}" | sed 's/v//g' >> $GITHUB_ENV + else + echo "IMAGE_VERSION=${{ env.IMAGE_VERSION }}-${{ github.run_number }}" >> $GITHUB_ENV + fi + - name: Login in to registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ env.REGISTRY_USERNAME }} + password: ${{ env.REGISTRY_PASSWORD }} + - name: Build and push docker image + uses: docker/build-push-action@v3 + with: + platforms: linux/amd64 + context: . + file: ./docker/Dockerfile + tags: ${{ env.CONTAINER_IMAGE_NAME }}:latest,${{ env.CONTAINER_IMAGE_NAME }}:${{ env.IMAGE_VERSION }} + push: true \ No newline at end of file From 79af05f2f995e3304ea432fb3c90557ca2c88909 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 5 Sep 2025 15:46:53 +0700 Subject: [PATCH 05/13] no message --- .forgejo/{workforws => workflows}/build.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .forgejo/{workforws => workflows}/build.yml (100%) diff --git a/.forgejo/workforws/build.yml b/.forgejo/workflows/build.yml similarity index 100% rename from .forgejo/workforws/build.yml rename to .forgejo/workflows/build.yml From c3741d139df271dae84e8c359d5a56b5172f040c Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Mon, 8 Sep 2025 10:21:28 +0700 Subject: [PATCH 06/13] file deploy --- .forgejo/workflows/deploy.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .forgejo/workflows/deploy.yml diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml new file mode 100644 index 0000000..4ef99d3 --- /dev/null +++ b/.forgejo/workflows/deploy.yml @@ -0,0 +1,29 @@ +name: Build + +on: + workflow_dispatch: + inputs: + version: + description: "Version to deploy" + type: string + required: false + default: "latest" + +env: + IMAGE_VERSION: build + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Remote Deploy + uses: appleboy/ssh-action@v1.2.1 + with: + host: ${{ vars.SSH_DEPLOY_HOST }} + port: ${{ vars.SSH_DEPLOY_PORT }} + username: ${{ secrets.SSH_DEPLOY_USER }} + password: ${{ secrets.SSH_DEPLOY_PASSWORD }} + script: | + cd ~/repo + ./replace-env.sh HRMS_USER "${{ inputs.version }}" + ./deploy.sh hrms-user From 115df31b90bf49d04820d45b7eb47f57a9ba20ae Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Mon, 8 Sep 2025 10:30:42 +0700 Subject: [PATCH 07/13] key --- .forgejo/workflows/deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml index 4ef99d3..2a82b7b 100644 --- a/.forgejo/workflows/deploy.yml +++ b/.forgejo/workflows/deploy.yml @@ -23,6 +23,7 @@ jobs: port: ${{ vars.SSH_DEPLOY_PORT }} username: ${{ secrets.SSH_DEPLOY_USER }} password: ${{ secrets.SSH_DEPLOY_PASSWORD }} + key: ${{ vars.SSH_PRIVATE_KEY }} script: | cd ~/repo ./replace-env.sh HRMS_USER "${{ inputs.version }}" From 8c4cf17684fcedf2cfb675b0ece02c835e774478 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Mon, 8 Sep 2025 10:37:02 +0700 Subject: [PATCH 08/13] test --- .forgejo/workflows/deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml index 2a82b7b..4ef99d3 100644 --- a/.forgejo/workflows/deploy.yml +++ b/.forgejo/workflows/deploy.yml @@ -23,7 +23,6 @@ jobs: port: ${{ vars.SSH_DEPLOY_PORT }} username: ${{ secrets.SSH_DEPLOY_USER }} password: ${{ secrets.SSH_DEPLOY_PASSWORD }} - key: ${{ vars.SSH_PRIVATE_KEY }} script: | cd ~/repo ./replace-env.sh HRMS_USER "${{ inputs.version }}" From 2fa9fcbb4cbdecdbdfc578579410aa7fd170e87d Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Mon, 8 Sep 2025 11:14:50 +0700 Subject: [PATCH 09/13] test --- .forgejo/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml index 4ef99d3..900559d 100644 --- a/.forgejo/workflows/deploy.yml +++ b/.forgejo/workflows/deploy.yml @@ -25,5 +25,5 @@ jobs: password: ${{ secrets.SSH_DEPLOY_PASSWORD }} script: | cd ~/repo - ./replace-env.sh HRMS_USER "${{ inputs.version }}" + ./replace-env.sh APP_USER "${{ inputs.version }}" ./deploy.sh hrms-user From 66cb55f50920fdd737ae6af300f8ce41fbb57a5e Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Mon, 8 Sep 2025 11:33:05 +0700 Subject: [PATCH 10/13] sort --- src/api/appeal/api.appeal.ts | 10 +-- src/components/TableD.vue | 6 +- .../Workflow/DialogSelectPerson.vue | 68 +++++++------------ .../Workflow/interface/request/Main.ts | 2 - .../components/TableListEvaluate.vue | 2 +- .../06_evaluate/views/EvaluateMain.vue | 9 ++- src/modules/07_appealComplain/views/Main.vue | 31 +++++---- .../10_registry/views/requestEditMain.vue | 26 ++++--- src/modules/13_portfolio/views/Main.vue | 5 -- src/modules/14_IDP/views/main.vue | 32 ++++++--- src/views/MainLayout.vue | 8 +++ 11 files changed, 102 insertions(+), 97 deletions(-) diff --git a/src/api/appeal/api.appeal.ts b/src/api/appeal/api.appeal.ts index 7fb0a1f..daa4886 100644 --- a/src/api/appeal/api.appeal.ts +++ b/src/api/appeal/api.appeal.ts @@ -7,15 +7,7 @@ export default { profileBykeycloak: () => `${profile}`, // positionBykeycloak: () => `${env.API_URI}/org/profile/keycloak/position`, - appealMainList: ( - status: string, - type: string, - year: number, - page: number, - pageSize: number, - keyword: string - ) => - `${appeal}/user?status=${status}&type=${type}&year=${year}&page=${page}&pageSize=${pageSize}&keyword=${keyword}`, + appealMainList: () => `${appeal}/user`, appealAdd: () => `${appeal}`, appealByID: (id: string) => `${appeal}/${id}`, diff --git a/src/components/TableD.vue b/src/components/TableD.vue index a669956..691aef7 100644 --- a/src/components/TableD.vue +++ b/src/components/TableD.vue @@ -138,9 +138,9 @@ function onRequest(requestProp: any) { ...newPagination, }; - if (isPageChange) { - emit("request", requestProp); - } + // if (isPageChange) { + emit("request", requestProp); + // } } function handlePageChange(newPage: number) { diff --git a/src/components/Workflow/DialogSelectPerson.vue b/src/components/Workflow/DialogSelectPerson.vue index 9dfae70..d2fc964 100644 --- a/src/components/Workflow/DialogSelectPerson.vue +++ b/src/components/Workflow/DialogSelectPerson.vue @@ -7,9 +7,9 @@ import http from "@/plugins/http"; import config from "@/app.config"; import type { QTableProps } from "quasar"; -import type { Pagination } from "@/components/Workflow/interface/index/Main"; import type { DataQuery } from "@/components/Workflow/interface/request/Main"; import type { DataCommander } from "@/components/Workflow/interface/response/Main"; +import type { PropsTable } from "@/interface/PropsTable"; import DialogHeader from "@/components/DialogHeader.vue"; @@ -76,17 +76,19 @@ const columns = ref([ style: "font-size: 14px", }, ]); - -const total = ref(0); -const totalList = ref(1); +const pagination = ref({ + sortBy: "", + descending: true, + page: 1, + rowsPerPage: 10, + rowsNumber: 0, +}); const isAcceptSetting = ref(false); const isApproveSetting = ref(false); const isReasonSetting = ref(false); const formDataQuery = reactive({ - page: 1, - pageSize: 10, isAct: false, keyword: "", }); @@ -97,12 +99,11 @@ async function fetchLists() { .put(config.API.workflow + `commander/${props.type}`, { ...formDataQuery, keycloakId: props.keycloakId, + page: pagination.value.page, + pageSize: pagination.value.rowsPerPage, }) .then(async (res) => { - totalList.value = Math.ceil( - res.data.result.total / formDataQuery.pageSize - ); - total.value = res.data.result.total; + pagination.value.rowsNumber = res.data.result.total; rows.value = res.data.result.data; }) .catch((err) => { @@ -139,7 +140,7 @@ function onSubmit() { } function onSearchData() { - formDataQuery.page = 1; + pagination.value.page = 1; fetchLists(); } @@ -150,32 +151,25 @@ function onCloseModal() { isAcceptSetting.value = false; isApproveSetting.value = false; isReasonSetting.value = false; - formDataQuery.page = 1; - formDataQuery.pageSize = 10; formDataQuery.isAct = false; formDataQuery.keyword = ""; } +/** + * ฟังก์ชันรับ request จากตาราง เมื่อมีการเปลี่ยน pagination + * @param requestProps ข้อมูลการร้องขอจากตาราง + */ +function onTableRequest(requestProps: PropsTable.RequestProps) { + const newPagination = requestProps?.pagination || requestProps; + if (!newPagination?.page || !newPagination?.rowsPerPage) return; + pagination.value = { ...newPagination }; +} + watch(modal, (val) => { if (val) { fetchLists(); } }); - -// watch( -// () => [formDataQuery.isAct, formDataQuery.pageSize], -// () => { -// onSearchData(); -// } -// ); - -/** - * function updatePagination - * @param newPagination ข้อมูล Pagination ใหม่ - */ -function updatePagination(newPagination: Pagination) { - formDataQuery.pageSize = newPagination.rowsPerPage; -}