| 
      
            Line 0
          
      
      
        Link Here
      
     | 
  
            
               | 
               | 
              1 | 
              <template>  | 
            
            
              | 2 | 
                  <WidgetWrapper v-bind="widgetWrapperProps">  | 
            
            
              | 3 | 
                      <template #default>  | 
            
            
              | 4 | 
                          <KohaTable  | 
            
            
              | 5 | 
                              ref="table"  | 
            
            
              | 6 | 
                              v-bind="tableOptions"  | 
            
            
              | 7 | 
                              :key="JSON.stringify(tableOptions)"  | 
            
            
              | 8 | 
                          />  | 
            
            
              | 9 | 
                      </template>  | 
            
            
              | 10 | 
                  </WidgetWrapper>  | 
            
            
              | 11 | 
              </template>  | 
            
            
              | 12 | 
               | 
            
            
              | 13 | 
              <script>  | 
            
            
              | 14 | 
              import { inject, ref, computed } from "vue"; | 
            
            
              | 15 | 
              import { storeToRefs } from "pinia"; | 
            
            
              | 16 | 
              import WidgetWrapper from "../WidgetWrapper.vue";  | 
            
            
              | 17 | 
              import KohaTable from "../../KohaTable.vue";  | 
            
            
              | 18 | 
              import { useBaseWidget } from "../../../composables/base-widget.js"; | 
            
            
              | 19 | 
              import { $__ } from "@koha-vue/i18n"; | 
            
            
              | 20 | 
               | 
            
            
              | 21 | 
              export default { | 
            
            
              | 22 | 
                  name: "ERMLicensesNeedingAction",  | 
            
            
              | 23 | 
                  components: { WidgetWrapper, KohaTable }, | 
            
            
              | 24 | 
                  props: { | 
            
            
              | 25 | 
                      display: String,  | 
            
            
              | 26 | 
                  },  | 
            
            
              | 27 | 
                  emits: ["removed", "added", "moveWidget"],  | 
            
            
              | 28 | 
                  setup(props, { emit }) { | 
            
            
              | 29 | 
                      const ERMStore = inject("ERMStore"); | 
            
            
              | 30 | 
                      const { get_lib_from_av } = ERMStore; | 
            
            
              | 31 | 
                      const { authorisedValues } = storeToRefs(ERMStore); | 
            
            
              | 32 | 
                      const av_license_statuses = authorisedValues.value.av_license_statuses;  | 
            
            
              | 33 | 
               | 
            
            
              | 34 | 
                      const table = ref();  | 
            
            
              | 35 | 
                      const default_settings = { | 
            
            
              | 36 | 
                          status: ["in_negotiation", "not_yet_active", "rejected"],  | 
            
            
              | 37 | 
                          per_page: 5,  | 
            
            
              | 38 | 
                      };  | 
            
            
              | 39 | 
                      const settings = ref(default_settings);  | 
            
            
              | 40 | 
                      const settings_definitions = ref([  | 
            
            
              | 41 | 
                          { | 
            
            
              | 42 | 
                              name: "status",  | 
            
            
              | 43 | 
                              type: "select",  | 
            
            
              | 44 | 
                              label: __("Status"), | 
            
            
              | 45 | 
                              showInTable: true,  | 
            
            
              | 46 | 
                              options: av_license_statuses.map(status => ({ | 
            
            
              | 47 | 
                                  value: status.value,  | 
            
            
              | 48 | 
                                  description: status.description,  | 
            
            
              | 49 | 
                              })),  | 
            
            
              | 50 | 
                              allowMultipleChoices: true,  | 
            
            
              | 51 | 
                              requiredKey: "value",  | 
            
            
              | 52 | 
                              selectLabel: "description",  | 
            
            
              | 53 | 
                          },  | 
            
            
              | 54 | 
                          { | 
            
            
              | 55 | 
                              name: "ended_on",  | 
            
            
              | 56 | 
                              type: "select",  | 
            
            
              | 57 | 
                              label: __("Ends in the next"), | 
            
            
              | 58 | 
                              showInTable: true,  | 
            
            
              | 59 | 
                              options: [  | 
            
            
              | 60 | 
                                  { value: "week", description: __("Week") }, | 
            
            
              | 61 | 
                                  { value: "two_weeks", description: __("Two weeks") }, | 
            
            
              | 62 | 
                                  { value: "month", description: __("Month") }, | 
            
            
              | 63 | 
                                  { value: "two_months", description: __("Two months") }, | 
            
            
              | 64 | 
                              ],  | 
            
            
              | 65 | 
                              requiredKey: "value",  | 
            
            
              | 66 | 
                              selectLabel: "description",  | 
            
            
              | 67 | 
                          },  | 
            
            
              | 68 | 
                          { | 
            
            
              | 69 | 
                              name: "per_page",  | 
            
            
              | 70 | 
                              type: "select",  | 
            
            
              | 71 | 
                              label: __("Show"), | 
            
            
              | 72 | 
                              showInTable: true,  | 
            
            
              | 73 | 
                              options: [  | 
            
            
              | 74 | 
                                  { value: 5, description: "5" }, | 
            
            
              | 75 | 
                                  { value: 10, description: "10" }, | 
            
            
              | 76 | 
                                  { value: 20, description: "20" }, | 
            
            
              | 77 | 
                              ],  | 
            
            
              | 78 | 
                              requiredKey: "value",  | 
            
            
              | 79 | 
                              selectLabel: "description",  | 
            
            
              | 80 | 
                          },  | 
            
            
              | 81 | 
                      ]);  | 
            
            
              | 82 | 
               | 
            
            
              | 83 | 
                      function settingsToQueryParams(settings) { | 
            
            
              | 84 | 
                          const params = {}; | 
            
            
              | 85 | 
               | 
            
            
              | 86 | 
                          if (settings.status && settings.status.length > 0) { | 
            
            
              | 87 | 
                              params["me.status"] = { | 
            
            
              | 88 | 
                                  "-in": settings.status,  | 
            
            
              | 89 | 
                              };  | 
            
            
              | 90 | 
                          }  | 
            
            
              | 91 | 
               | 
            
            
              | 92 | 
                          if (settings.ended_on) { | 
            
            
              | 93 | 
                              const now = new Date();  | 
            
            
              | 94 | 
                              let limitDate;  | 
            
            
              | 95 | 
               | 
            
            
              | 96 | 
                              switch (settings.ended_on) { | 
            
            
              | 97 | 
                                  case "week":  | 
            
            
              | 98 | 
                                      limitDate = new Date(now.setDate(now.getDate() + 7));  | 
            
            
              | 99 | 
                                      break;  | 
            
            
              | 100 | 
                                  case "two_weeks":  | 
            
            
              | 101 | 
                                      limitDate = new Date(now.setDate(now.getDate() + 14));  | 
            
            
              | 102 | 
                                      break;  | 
            
            
              | 103 | 
                                  case "month":  | 
            
            
              | 104 | 
                                      limitDate = new Date(now.setMonth(now.getMonth() + 1));  | 
            
            
              | 105 | 
                                      break;  | 
            
            
              | 106 | 
                                  case "two_months":  | 
            
            
              | 107 | 
                                      limitDate = new Date(now.setMonth(now.getMonth() + 2));  | 
            
            
              | 108 | 
                                      break;  | 
            
            
              | 109 | 
                              }  | 
            
            
              | 110 | 
               | 
            
            
              | 111 | 
                              if (limitDate) { | 
            
            
              | 112 | 
                                  params["me.ended_on"] = { "<=": limitDate }; | 
            
            
              | 113 | 
                              }  | 
            
            
              | 114 | 
                          }  | 
            
            
              | 115 | 
               | 
            
            
              | 116 | 
                          return params;  | 
            
            
              | 117 | 
                      }  | 
            
            
              | 118 | 
               | 
            
            
              | 119 | 
                      const tableOptions = computed(() => ({ | 
            
            
              | 120 | 
                          columns: [  | 
            
            
              | 121 | 
                              { | 
            
            
              | 122 | 
                                  title: __("Name"), | 
            
            
              | 123 | 
                                  data: "name",  | 
            
            
              | 124 | 
                                  searchable: true,  | 
            
            
              | 125 | 
                                  orderable: true,  | 
            
            
              | 126 | 
                                  render(data, type, row) { | 
            
            
              | 127 | 
                                      const name = escape_str(row.name);  | 
            
            
              | 128 | 
                                      const shortName =  | 
            
            
              | 129 | 
                                          name.length > 25  | 
            
            
              | 130 | 
                                              ? name.substring(0, 22) + "..."  | 
            
            
              | 131 | 
                                              : name;  | 
            
            
              | 132 | 
                                      return `<a href="/cgi-bin/koha/erm/licenses/${row.license_id}" class="show">${shortName}</a>`; | 
            
            
              | 133 | 
                                  },  | 
            
            
              | 134 | 
                              },  | 
            
            
              | 135 | 
                              { | 
            
            
              | 136 | 
                                  title: __("Type"), | 
            
            
              | 137 | 
                                  data: "type",  | 
            
            
              | 138 | 
                                  searchable: true,  | 
            
            
              | 139 | 
                                  orderable: true,  | 
            
            
              | 140 | 
                                  render(data, type, row) { | 
            
            
              | 141 | 
                                      return escape_str(  | 
            
            
              | 142 | 
                                          get_lib_from_av("av_license_types", row.type) | 
            
            
              | 143 | 
                                      );  | 
            
            
              | 144 | 
                                  },  | 
            
            
              | 145 | 
                              },  | 
            
            
              | 146 | 
                              { | 
            
            
              | 147 | 
                                  title: __("Status"), | 
            
            
              | 148 | 
                                  data: "status",  | 
            
            
              | 149 | 
                                  searchable: true,  | 
            
            
              | 150 | 
                                  orderable: true,  | 
            
            
              | 151 | 
                                  render(data, type, row) { | 
            
            
              | 152 | 
                                      return escape_str(  | 
            
            
              | 153 | 
                                          get_lib_from_av("av_license_statuses", row.status) | 
            
            
              | 154 | 
                                      );  | 
            
            
              | 155 | 
                                  },  | 
            
            
              | 156 | 
                              },  | 
            
            
              | 157 | 
                              { | 
            
            
              | 158 | 
                                  title: __("Ends on"), | 
            
            
              | 159 | 
                                  data: "ended_on",  | 
            
            
              | 160 | 
                                  searchable: true,  | 
            
            
              | 161 | 
                                  orderable: true,  | 
            
            
              | 162 | 
                                  render(data, type, row) { | 
            
            
              | 163 | 
                                      return $date(row.ended_on);  | 
            
            
              | 164 | 
                                  },  | 
            
            
              | 165 | 
                              },  | 
            
            
              | 166 | 
                          ],  | 
            
            
              | 167 | 
                          options: { | 
            
            
              | 168 | 
                              dom: "t",  | 
            
            
              | 169 | 
                              embed: "vendor,extended_attributes,+strings",  | 
            
            
              | 170 | 
                              pageLength: settings.value.per_page || 5,  | 
            
            
              | 171 | 
                          },  | 
            
            
              | 172 | 
                          url: "/api/v1/erm/licenses",  | 
            
            
              | 173 | 
                          default_filters: settingsToQueryParams(settings.value),  | 
            
            
              | 174 | 
                      }));  | 
            
            
              | 175 | 
               | 
            
            
              | 176 | 
                      const baseWidget = useBaseWidget(  | 
            
            
              | 177 | 
                          { | 
            
            
              | 178 | 
                              id: "ERMLicensesNeedingAction",  | 
            
            
              | 179 | 
                              name: $__("Licenses needing action"), | 
            
            
              | 180 | 
                              icon: "fa fa-gavel",  | 
            
            
              | 181 | 
                              description: $__(  | 
            
            
              | 182 | 
                                  "Show licenses that need action. It filters licenses by status and end date. This widget is configurable."  | 
            
            
              | 183 | 
                              ),  | 
            
            
              | 184 | 
                              loading: false,  | 
            
            
              | 185 | 
                              settings: settings,  | 
            
            
              | 186 | 
                              settings_definitions: settings_definitions,  | 
            
            
              | 187 | 
                              ...props,  | 
            
            
              | 188 | 
                          },  | 
            
            
              | 189 | 
                          emit  | 
            
            
              | 190 | 
                      );  | 
            
            
              | 191 | 
               | 
            
            
              | 192 | 
                      return { | 
            
            
              | 193 | 
                          ...baseWidget,  | 
            
            
              | 194 | 
                          table,  | 
            
            
              | 195 | 
                          tableOptions,  | 
            
            
              | 196 | 
                      };  | 
            
            
              | 197 | 
                  },  | 
            
            
              | 198 | 
              };  | 
            
            
              | 199 | 
              </script>  |