Skip to content
Snippets Groups Projects
UpdateItem.vue 26.2 KiB
Newer Older
moon's avatar
moon committed
    <base-toaster
      :open="toasterIsOpen"
      @close="hideDialog"
    >
      <div class="flex justify-between items-center">
        <font-awesome-icon
          class="ml-3"
          icon="fa-solid fa-thumbs-up "
          size="lg"
        />

        <h4>Request updated successfully!</h4>
moon's avatar
moon committed
        <button
          class="btn btn-outline"
          @click="hideDialog"
        >
          <font-awesome-icon
            icon="fa-regular fa-circle-xmark"
            size="2x"
          />
    <div class="flex items-center justify-center">
moon's avatar
moon committed
      <h3
        v-show="error && !jwt"
        class="text-2xl text-red-500"
      >
moon's avatar
moon committed
        {{ errorMsg }}
      </h3>
      <div
        v-if="item === 'new' || loaded"
        class="md:flex w-3/5 border border-gray-300 rounded-lg p-2 mt-5"
moon's avatar
moon committed
      >
        <div
          class="p-5 mx-auto text-left font-raleway container max-w-screen-md"
        >
          <h1
            class="
              font-bold
              text-left
              font-montserrat
              text-3xl
              sm:text-5xl
              mb-7
            "
          >
            {{ item === "new" ? "Create new Update Item" : item }}
moon's avatar
moon committed
          <form
            class="w-full md:w-auto"
            @submit.prevent="updateReview"
          >
moon's avatar
moon committed
            <div class="md:flex md:items-center mx-3 mb-6">
              <div class="md:w-1/3">
                <label
                  class="text-left font-bold md:text-right mb-1 md:mb-0 pr-4"
                  for="inline-entity-type"
                >
                  Entity Type
                </label>
              </div>
              <div class="md:w-2/3">
moon's avatar
moon committed
                  id="inline-entity-type"
                  v-model="entity"
                  disabled
                  class="
                    bg-white
                    w-full
                    py-2
                    text-gray-700
                    bg-transparent
                    border-b
                    hover:border-gray-700
                    focus:bg-gray-200 focus:border-blue-700
                  "
                >
moon's avatar
moon committed
                  <option
                    disabled
                    value=""
                  >
                    Please select one
                  </option>
                  <option>protein</option>
                  <option>condensate</option>
                  <option>condensate_protein</option>
moon's avatar
moon committed
            <div class="md:flex md:items-center mx-3 mb-6">
              <div class="md:w-1/3">
                <label
                  class="text-left font-bold md:text-right mb-1 md:mb-0 pr-4"
                  for="inline-entity-id"
                >
                  Entity ID
                </label>
              </div>
              <div class="md:w-2/3">
moon's avatar
moon committed
                  id="inline-entity-id"
moon's avatar
moon committed
                  disabled
                  class="
                    bg-white
                    w-full
                    py-2
                    text-gray-700
                    outline-none
                    bg-transparent
                    border-b
                    hover:border-gray-700
                    focus:bg-gray-200 focus:border-blue-700
                  "
                  type="text"
                  placeholder="UNE6"
moon's avatar
moon committed
                >
moon's avatar
moon committed
            <div class="md:flex md:items-center mx-3 mb-6">
              <div class="md:w-1/3">
                <label
                  class="text-left font-bold md:text-right mb-1 md:mb-0 pr-4"
                  for="inline-change-operation"
                >
                  Change Operation
                </label>
              </div>
              <div class="md:w-2/3">
moon's avatar
moon committed
                  id="inline-change-operation"
moon's avatar
moon committed
                  disabled
                  class="
                    bg-white
                    w-full
                    py-2
                    text-gray-700
                    outline-none
                    bg-transparent
                    border-b
                    hover:border-gray-700
                    focus:bg-gray-200 focus:border-blue-700
                  "
                >
moon's avatar
moon committed
                  <option
                    disabled
                    value=""
                  >
                    Please select one
                  </option>
                  <option>add</option>
                  <option>remove</option>
                  <option>update</option>
moon's avatar
moon committed
            <div class="md:flex md:items-center mx-3 mb-6">
              <div class="md:w-1/3">
                <label
                  class="text-left font-bold md:text-right mb-1 md:mb-0 pr-4"
                  for="inline-attribute-name"
                >
                  Attribute Name
                </label>
              </div>
              <div class="md:w-2/3">
moon's avatar
moon committed
                  id="inline-attribute-name"
moon's avatar
moon committed
                  disabled
                  class="
                    bg-white
                    w-full
                    py-2
                    text-gray-700
                    outline-none
                    bg-transparent
                    border-b
                    hover:border-gray-700
                    focus:bg-gray-200 focus:border-blue-700
                  "
                  type="text"
                  placeholder="functional_type"
moon's avatar
moon committed
                >
moon's avatar
moon committed
            <div class="md:flex md:items-center mx-3 mb-6">
              <div class="md:w-1/3">
                <label
                  class="text-left font-bold md:text-right mb-1 md:mb-0 pr-4"
                  for="inline-attribute-value"
                >
                  Attribute Value
                </label>
              </div>
              <div class="md:w-2/3">
moon's avatar
moon committed
                  id="inline-attribute-value"
moon's avatar
moon committed
                  disabled
                  class="
                    bg-white
                    w-full
                    py-2
                    text-gray-700
                    outline-none
                    bg-transparent
                    border-b
                    hover:border-gray-700
                    focus:bg-gray-200 focus:border-blue-700
                  "
                  type="text"
                  placeholder="driver"
moon's avatar
moon committed
                >
moon's avatar
moon committed
            <div class="md:flex md:items-center mx-3 mb-6">
              <div class="md:w-1/3">
                <label
                  class="text-left font-bold md:text-right mb-1 md:mb-0 pr-4"
                  for="inline-comment"
                >
moon's avatar
moon committed
                </label>
              </div>
              <div class="md:w-2/3">
moon's avatar
moon committed
                  id="inline-comment"
                  v-model="submissionComments"
                  disabled
                  rows="5"
                  class="
                    bg-white
                    w-full
                    py-2
                    text-gray-700
                    outline-none
                    bg-transparent
                    border-b
                    hover:border-gray-700
                    focus:bg-gray-200 focus:border-blue-700
                  "
                  type="text"
                  placeholder="your comments here"
moon's avatar
moon committed
                />
moon's avatar
moon committed
              </div>
            </div>

            <div
              v-if="item !== 'new'"
              class="md:flex md:items-center mx-3 mb-6"
            >
              <div class="md:w-1/3">
                <label
                  class="text-left font-bold md:text-right mb-1 md:mb-0 pr-4"
                  for="inline-status"
                >
                  Status
                </label>
              </div>
              <div class="md:w-2/3">
                <p
                  v-if="
                    (userRole === 'Contributor' ||
                      userRole === 'Maintainer' ||
                      userRole === 'Administrator') &&
moon's avatar
moon committed
                      itemId !== 'new'
moon's avatar
moon committed
                  :class="colorChange"
                  class="
                    rounded-full
                    font-bold
                    capitalize
                    mt-3
                    px-4
                    mr-2
                    w-40
                    text-white
                    p-2
                    rounded
                    flex
                    items-center
                    justify-center
                  "
moon's avatar
moon committed
                  <!-- <div class="rounded-full px-4 mr-2 bg-gray-500 text-white p-2 rounded flex items-center justify-center">${sData}</div> -->
moon's avatar
moon committed
                </p>
            <div
              v-if="item !== 'new' && reviewedBy.data"
              class="md:flex md:items-center mx-3 mb-6"
            >
              <div class="md:w-1/3">
                <label
                  class="text-left font-bold md:text-right mb-1 md:mb-0 pr-4"
                  for="inline-status"
                >
                  Reviewer
                </label>
              </div>
              <div class="md:w-2/3">
                <p class="mt-3">
                  {{ reviewedBy.data.attributes.full_name }}
                </p>
              </div>
            </div>
            <div
              v-if="item !== 'new' && reviewedBy.data"
              class="md:flex md:items-center mx-3 mb-6"
            >
              <div class="md:w-1/3">
                <label
                  class="text-left font-bold md:text-right mb-1 md:mb-0 pr-4"
                  for="inline-status"
                >
                </label>
              </div>
              <div class="md:w-2/3">

            <!-- <button
              v-if="item !== 'new' && userRole !== 'Maintainer'"
              type="submit"
              :disabled="entityId.length < 3"
              class="bg-green-400 p-5 text-white"
            >
              {{ item === "new" ? "Submit" : "Update" }}
              <span class="fa fa-arrow-right" />
            </button> -->
moon's avatar
moon committed
            <div
              v-if="status != 'rejected'"
moon's avatar
moon committed
              class="md:flex md:items-center mx-3 mb-6"
            >
              <div class="md:w-1/3">
                <label
                  class="text-left font-bold md:text-right mb-1 md:mb-0 pr-4"
                  for="inline-reviewer-comment"
                >
                  Sync Response
                </label>
moon's avatar
moon committed
              <div class="md:w-2/3">
                <p
                  v-if="!syncResponse"
                  class="
                    mt-3
                    px-4
                    mr-2
                    w-full
                    bg-gray-300
                    p-2
                    flex
                    items-center
                    justify-center
                  "
moon's avatar
moon committed
                >
                  Yet to be synced.
                </p>
moon's avatar
moon committed
                <p
                  v-else
                  class="mt-3"
                >
                  {{ syncResponse }}
moon's avatar
moon committed
                </p>
              </div>
            </div>
            <div
              v-if="status != 'rejected'"
moon's avatar
moon committed
              class="md:flex md:items-center mx-3 mb-6"
            >
              <div class="md:w-1/3">
                <label
                  class="text-left font-bold md:text-right mb-1 md:mb-0 pr-4"
                  for="inline-reviewer-comment"
                >
                  Synced At
                </label>
moon's avatar
moon committed
              <div class="md:w-2/3">
                <p
                  v-if="!syncedAt"
                  class="
                    mt-3
                    px-4
                    mr-2
                    w-full
                    bg-gray-300
                    p-2
                    flex
                    items-center
                    justify-center
                  "
moon's avatar
moon committed
                >
                  Yet to be synced.
                </p>
moon's avatar
moon committed
                <p
                  v-else
                  class="mt-3"
                >
moon's avatar
moon committed
                  {{ syncedAt }}
                </p>
              </div>
            </div>
moon's avatar
moon committed
                  item !== 'new' &&
                  status != 'synced'
              "
              class="mt-10"
            >
              <div class="relative flex py-5 items-center">
moon's avatar
moon committed
                <div class="flex-grow border-t border-gray-400" />
moon's avatar
moon committed
                <span
                  class="flex-shrink mx-4 text-gray-400"
                >Reviewer Section</span>
moon's avatar
moon committed
                <div class="flex-grow border-t border-gray-400" />
moon's avatar
moon committed
                <base-spinner />
moon's avatar
moon committed
              <h3 class="mb-6">
                Reviewer Action
              </h3>
              <div class="md:flex md:items-center mx-3 mb-6">
                <div class="md:w-1/3">
                  <label
                    class="text-left font-bold md:text-right mb-1 md:mb-0 pr-4"
                    for="inline-status"
                  >
                    Change Status to
                  </label>
                </div>
                <div class="md:w-2/3">
moon's avatar
moon committed
                      id="inline-status"
                        hover:border-gray-700
                        focus:bg-gray-200 focus:border-gray-700
                      "
moon's avatar
moon committed
                      @change="validateStatusChange"
                      <!-- <option value="Select" selected disabled>Select</option>
moon's avatar
moon committed
                      <option
                        v-for="action in reqActions"
                        :key="action"
                        :value="action"
                      >
                        {{ action }}
                      </option>
                </div>
              </div>

              <div class="md:flex md:items-center mx-3 mb-6">
                <div class="md:w-1/3">
                  <label
                    class="text-left font-bold md:text-right mb-1 md:mb-0 pr-4"
                    for="inline-reviewer-comment"
                  >
                    Reviewer Comment
                  </label>
                </div>
                <div class="md:w-2/3">
moon's avatar
moon committed
                      id="inline-reviewer-comment"
moon's avatar
moon committed
                      rows="5"
                      placeholder="Reviewer comments here"
moon's avatar
moon committed
                      @keyup="validateReviewerCmt"
                    />
                    v-if="error && reviewerCmtErrMsg"
                    class="text-2xl text-red-500"
                  >
                    {{ reviewerCmtErrMsg }}
              <!-- <div class="md:flex md:items-center mx-3 mb-6">
                  <label class="text-left font-bold md:text-right mb-1 md:mb-0 pr-4" for="inline-reviewer-comment">
                    Sync Response
                  </label>
                </div>
                <div class="md:w-2/3">
                  <p class="mt-3">
              </div> -->
            </div>
            <div class="flex space-x-4">
moon's avatar
moon committed
              <button
                v-if="
                  userRole === 'Maintainer' &&
moon's avatar
moon committed
                    item !== 'new' &&
                    status != 'synced'
                type="submit"
                :disabled="entityId.length < 3"
                  hover:bg-blue-700
                  focus:ring-2 focus:ring-blue-300
                  rounded-lg
                  inline-flex
                  items-center
                  px-5
                  py-2.5
                  text-center
                {{ "Update Review" }}
moon's avatar
moon committed
                <button
                  type="button"
                  class="
                    bg-gray
                    group-hover:bg-gray-400 group-hover:text-white
                    focus:ring-2 focus:ring-gray-300
                    rounded-lg
                    border border-gray-300
                    px-5
                    py-3
                    hover:text-gray-900
                    font-bold
                  "
moon's avatar
moon committed
                  @click="$router.go(-1)"
                >
                  Back
                </button>
moon's avatar
moon committed
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
moon's avatar
moon committed
import BaseSpinner from '../components/UI/BaseSpinner.vue';
import BaseToaster from '../components/UI/BaseToaster.vue';
let host = require('@/components/js/const').apiHost;
moon's avatar
moon committed
  name: 'UpdateItem',
moon's avatar
moon committed
  components: { BaseSpinner, BaseToaster },
moon's avatar
moon committed
  props: ['itemId'],
  data() {
    return {
      item: this.$route.params.item ? this.$route.params.item : this.itemId,
moon's avatar
moon committed
      entity: 'protein', // [protein, condensate, condensate_protein]
      entityId: '', // protein: <uniprot_id>, condensate: <canonical_id>, condensate_protein: <uniprot_id>==<canonical_id>
      changeOperation: 'add', // add/remove/update/update_add/update_remove
      attribute: '', // protein: functional_type[driver/client/regulator], pubmed_ids[]
      // condensate: description, proteins
      // condensate_protein: confidence_score, pubmed_ids
moon's avatar
moon committed
      attributeValue: '', // the value of the attribute to be updated. Could be "null" for add/remove operations. The data type is dynamic
      status: 'requested', // 1. requested, 2. accepted, 3. rejected, 4. synced
      reviewerStatus: 'Choose an action',
      submittedBy: '',
      submittedAt: '', // datetime
      submissionComments: '',
      reviewedBy: '',
      reviewedAt: '', // datetime
      reviewComments: '',
      reviewerComments: '',
      syncedAt: '', // datetime
      syncResponse: '', // response from the sync process (errors if any)
      loaded: false,
      errorMsg: `An error occurred, please try again`,
moon's avatar
moon committed
      statusErrMsg: '',
      reviewerCmtErrMsg: '',
moon's avatar
moon committed
      actionErrMsg: '',
      isDev: process.env.NODE_ENV === 'development',
      reqActions: ['Choose an action', 'accepted', 'rejected'],
  },
  computed: {
    jwt: function () {
moon's avatar
moon committed
      return this.$store.getters['User/jwt'];
    },
    userData: function () {
moon's avatar
moon committed
      return this.$store.getters['User/userData'];
    },
    userRole: function () {
moon's avatar
moon committed
      return this.$store.getters['User/userRole'];
    colorChange() {
moon's avatar
moon committed
      if (this.status === 'rejected') {
        return `bg-red-500`;
moon's avatar
moon committed
      } else if (this.status === 'requested') {
        return `bg-yellow-500`;
moon's avatar
moon committed
      } else if (this.status === 'synced') {
        return `bg-gray-500`;
moon's avatar
moon committed
      } else if (this.status === 'accepted') {
        return `bg-green-500`;
moon's avatar
moon committed
      return '';
moon's avatar
moon committed
  mounted: async function () {
    const vm = this;

    const jwt = vm.jwt;
    if (jwt === null) {
moon's avatar
moon committed
      vm.$router.push('/login');
moon's avatar
moon committed
    } else {
moon's avatar
moon committed
      if (vm.item !== 'new') {
moon's avatar
moon committed
        vm.load(vm.item);
      }
    }
  },
    showDialog() {
      this.toasterIsOpen = true;
    },
    hideDialog() {
      this.toasterIsOpen = false;
    },
    validateReviewerCmt() {
      this.error = false;
moon's avatar
moon committed
      this.reviewerCmtErrMsg = '';
    },
    validateStatusChange() {
      this.error = false;
moon's avatar
moon committed
      this.statusErrMsg = '';
    async update(e) {
      const vm = this;

moon's avatar
moon committed
        host = require('@/components/js/const').devApiHost;
        vm.loaded = false;
      }

      // console.log(vm.userData)
      let dat = {
        Entity: this.entity,
        EntityId: this.entityId,
        Attribute: this.attribute,
        Value: this.attributeValue,
        ChangeOperation: this.changeOperation,
        SubmissionComments: this.submissionComments,
moon's avatar
moon committed
        Status: vm.userRole === 'Maintainer' ? 'accepted' : this.status,
        // ReviewedBy:
        // ReviewedAt:
        // ReviewComment:
        // SyncedAt:
        // SyncResponse:
      };

      try {
moon's avatar
moon committed
        if (vm.item !== 'new') {
          const res = await this.axios.put(
            `${host}/api/update-items/` + vm.item,
            {
              data: dat,
            },
            {
              headers: {
                Authorization: `Bearer ${jwt}`,
              },
          const res = await this.axios.post(
            `${host}/api/update-items`,
            {
              data: dat,
            },
            {
              headers: {
                Authorization: `Bearer ${jwt}`,
              },
moon's avatar
moon committed
        vm.$router.push('/profile');
        // console.log(error.response.data.error.message)
        // console.log(error.response)
      }
    },
    async load(id) {
      const vm = this;

moon's avatar
moon committed
        host = require('@/components/js/const').devApiHost;
      const jwt = vm.jwt;
        vm.loaded = false;
      }

      // console.log(vm.userData)
      vm.isLoading = true;
        const res = await this.axios.get(`${host}/api/update-items/` + id, {
        console.log(res.data.data);
          const d = res.data.data.attributes;
          vm.item = res.data.data.id;
          vm.entity = d.Entity;
          vm.entityId = d.EntityId;
          vm.attribute = d.Attribute;
          vm.attributeValue = d.Value;
          vm.changeOperation = d.ChangeOperation;
          vm.status = d.Status;
          vm.submissionComments = d.SubmissionComments;
          vm.reviewerComments = d.ReviewComments;
          vm.reviewedBy = d.reviewedBy;
          vm.reviewedAt = d.ReviewedAt;
          // ReviewedBy:
          // ReviewedAt:
          // ReviewComment:
          vm.syncedAt = d.SyncedAt;
          vm.syncResponse = d.SyncResponse;
        vm.isLoading = false;
        vm.loaded = true;
        // console.error(error)
moon's avatar
moon committed
        this.errorMsg = 'You are not authorized to access this item.';
        vm.isLoading = false;
        setTimeout(() => vm.$router.go(-1), 2000);
    },
    async updateReview() {
      const vm = this;

moon's avatar
moon committed
        host = require('@/components/js/const').devApiHost;
moon's avatar
moon committed
      if (!this.reviewerStatus || this.reviewerStatus === 'Choose an action') {
        console.log('in update review true');
moon's avatar
moon committed
        this.statusErrMsg = 'Please select an action.';
      } else if (this.reviewerStatus === this.status) {
        this.error = true;
        this.statusErrMsg =
moon's avatar
moon committed
          'The new change status is same as previous. Please select another value.';
      } else if (!this.reviewComments) {
moon's avatar
moon committed
        this.reviewerCmtErrMsg = 'Comment should not be empty!';
      }
      // console.log(vm.userData)
      let dat = {
        ReviewComments: this.reviewComments,
        await this.axios.put(
          `${host}/api/update-item/review/` + vm.item,
          {
            data: dat,
          },
          {
            headers: {
              Authorization: `Bearer ${jwt}`,
            },
moon's avatar
moon committed
        this.reviewComments = '';
        this.isLoading = false;
        this.toasterIsOpen = true;
          this.toasterIsOpen = false;
          this.load(this.item);
        // console.log(error.response.data.error.message)
        // console.log(error.response)
        vm.isLoading = false;
@import url("~@/assets/bootstrap.css");
  color: #ef0087 !important;