Browse Source

Resolve conversations

zhixin 3 years ago
parent
commit
69ccb286dd

+ 64 - 72
src/extensions/cookie/bootstrap-table-cookie.js

@@ -19,59 +19,39 @@ const UtilsCookie = {
     filterBy: 'bs.table.filterBy'
     filterBy: 'bs.table.filterBy'
   },
   },
   getCurrentHeader (that) {
   getCurrentHeader (that) {
-    let header = that.$header
-
-    if (that.options.height) {
-      header = that.$tableHeader
-    }
-
-    return header
+    return that.options.height ? that.$tableHeader : that.$header
   },
   },
   getCurrentSearchControls (that) {
   getCurrentSearchControls (that) {
-    let searchControls = 'select, input'
-
-    if (that.options.height) {
-      searchControls = 'table select, table input'
-    }
-
-    return searchControls
+    return that.options.height ? 'table select, table input' : 'select, input'
   },
   },
   isCookieSupportedByBrowser () {
   isCookieSupportedByBrowser () {
-    return !!(navigator.cookieEnabled)
+    return navigator.cookieEnabled
   },
   },
   isCookieEnabled (that, cookieName) {
   isCookieEnabled (that, cookieName) {
-    return that.options.cookiesEnabled.indexOf(cookieName) !== -1
+    return that.options.cookiesEnabled.includes(cookieName)
   },
   },
   setCookie (that, cookieName, cookieValue) {
   setCookie (that, cookieName, cookieValue) {
-    if (!that.options.cookie) {
-      return
-    }
-
-    if (!UtilsCookie.isCookieEnabled(that, cookieName)) {
+    if (
+      !that.options.cookie ||
+      !UtilsCookie.isCookieEnabled(that, cookieName)
+    ) {
       return
       return
     }
     }
 
 
-    cookieName = `${that.options.cookieIdTable}.${cookieName}`
-
-    return that._storage.setItem(cookieName, cookieValue)
+    return that._storage.setItem(`${that.options.cookieIdTable}.${cookieName}`, cookieValue)
   },
   },
-  getCookie (that, tableName, cookieName) {
-    if (!cookieName) {
-      return null
-    }
-
-    if (!UtilsCookie.isCookieEnabled(that, cookieName)) {
+  getCookie (that, cookieName) {
+    if (
+      !cookieName ||
+      !UtilsCookie.isCookieEnabled(that, cookieName)
+    ) {
       return null
       return null
     }
     }
 
 
-    cookieName = `${tableName}.${cookieName}`
-
-    return that._storage.getItem(cookieName)
+    return that._storage.getItem(`${that.options.cookieIdTable}.${cookieName}`)
   },
   },
   deleteCookie (that, cookieName) {
   deleteCookie (that, cookieName) {
-    cookieName = `${that.options.cookieIdTable}.${cookieName}`
-
-    return that._storage.removeItem(cookieName)
+    return that._storage.removeItem(`${that.options.cookieIdTable}.${cookieName}`)
   },
   },
   calculateExpiration (cookieExpire) {
   calculateExpiration (cookieExpire) {
     const time = cookieExpire.replace(/[0-9]*/, '') // s,mi,h,d,m,y
     const time = cookieExpire.replace(/[0-9]*/, '') // s,mi,h,d,m,y
@@ -111,43 +91,55 @@ const UtilsCookie = {
   },
   },
   initCookieFilters (bootstrapTable) {
   initCookieFilters (bootstrapTable) {
     setTimeout(() => {
     setTimeout(() => {
-      const parsedCookieFilters = JSON.parse(UtilsCookie.getCookie(bootstrapTable, bootstrapTable.options.cookieIdTable, UtilsCookie.cookieIds.filterControl))
+      const parsedCookieFilters = JSON.parse(
+        UtilsCookie.getCookie(bootstrapTable, UtilsCookie.cookieIds.filterControl))
 
 
       if (!bootstrapTable._filterControlValuesLoaded && parsedCookieFilters) {
       if (!bootstrapTable._filterControlValuesLoaded && parsedCookieFilters) {
-
         const cachedFilters = {}
         const cachedFilters = {}
         const header = UtilsCookie.getCurrentHeader(bootstrapTable)
         const header = UtilsCookie.getCurrentHeader(bootstrapTable)
         const searchControls = UtilsCookie.getCurrentSearchControls(bootstrapTable)
         const searchControls = UtilsCookie.getCurrentSearchControls(bootstrapTable)
 
 
         const applyCookieFilters = (element, filteredCookies) => {
         const applyCookieFilters = (element, filteredCookies) => {
           filteredCookies.forEach(cookie => {
           filteredCookies.forEach(cookie => {
-            if (cookie.text === '' || (element.type === 'radio' && element.value.toString() !== cookie.text.toString())) {
+            const value = element.value.toString()
+            const text = cookie.text
+
+            if (
+              text === '' ||
+              element.type === 'radio' &&
+              value !== text
+            ) {
               return
               return
             }
             }
 
 
-            if (element.tagName === 'INPUT' && element.type === 'radio' && element.value.toString() === cookie.text.toString()) {
+            if (
+              element.tagName === 'INPUT' &&
+              element.type === 'radio' &&
+              value === text
+            ) {
               element.checked = true
               element.checked = true
-              cachedFilters[cookie.field] = cookie.text
+              cachedFilters[cookie.field] = text
             } else if (element.tagName === 'INPUT') {
             } else if (element.tagName === 'INPUT') {
-              element.value = cookie.text
-              cachedFilters[cookie.field] = cookie.text
-            } else if (element.tagName === 'SELECT' && bootstrapTable.options.filterControlContainer) {
-              element.value = cookie.text
-              cachedFilters[cookie.field] = cookie.text
-            } else if (cookie.text !== '' && element.tagName === 'SELECT') {
-              cachedFilters[cookie.field] = cookie.text
-              for (let i = 0; i < element.length; i++) {
-                const currentElement = element[i]
-
-                if (currentElement.value === cookie.text) {
+              element.value = text
+              cachedFilters[cookie.field] = text
+            } else if (
+              element.tagName === 'SELECT' &&
+              bootstrapTable.options.filterControlContainer
+            ) {
+              element.value = text
+              cachedFilters[cookie.field] = text
+            } else if (text !== '' && element.tagName === 'SELECT') {
+              cachedFilters[cookie.field] = text
+              for (const currentElement of element) {
+                if (currentElement.value === text) {
                   currentElement.selected = true
                   currentElement.selected = true
                   return
                   return
                 }
                 }
               }
               }
               const option = document.createElement('option')
               const option = document.createElement('option')
 
 
-              option.value = cookie.text
-              option.text = cookie.text
+              option.value = text
+              option.text = text
               element.add(option, element[1])
               element.add(option, element[1])
               element.selectedIndex = 1
               element.selectedIndex = 1
             }
             }
@@ -222,7 +214,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
       this.configureStorage()
       this.configureStorage()
 
 
       // FilterBy logic
       // FilterBy logic
-      const filterByCookieValue = UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.filterBy)
+      const filterByCookieValue = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.filterBy)
 
 
       if (typeof filterByCookieValue === 'boolean' && !filterByCookieValue) {
       if (typeof filterByCookieValue === 'boolean' && !filterByCookieValue) {
         throw new Error('The cookie value of filterBy must be a json!')
         throw new Error('The cookie value of filterBy must be a json!')
@@ -279,7 +271,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
       this.options.filterControl &&
       this.options.filterControl &&
       !this._filterControlValuesLoaded
       !this._filterControlValuesLoaded
     ) {
     ) {
-      const cookie = JSON.parse(UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.filterControl))
+      const cookie = JSON.parse(UtilsCookie.getCookie(this, UtilsCookie.cookieIds.filterControl))
 
 
       if (cookie) {
       if (cookie) {
         return
         return
@@ -301,11 +293,11 @@ $.BootstrapTable = class extends $.BootstrapTable {
     }
     }
 
 
     if (this.options.sortName === undefined || this.options.sortOrder === undefined) {
     if (this.options.sortName === undefined || this.options.sortOrder === undefined) {
-      UtilsCookie.deleteCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.sortName)
-      UtilsCookie.deleteCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.sortOrder)
+      UtilsCookie.deleteCookie(this, UtilsCookie.cookieIds.sortName)
+      UtilsCookie.deleteCookie(this, UtilsCookie.cookieIds.sortOrder)
     } else {
     } else {
       this.options.sortPriority = null
       this.options.sortPriority = null
-      UtilsCookie.deleteCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.sortPriority)
+      UtilsCookie.deleteCookie(this, UtilsCookie.cookieIds.sortPriority)
 
 
       UtilsCookie.setCookie(this, UtilsCookie.cookieIds.sortOrder, this.options.sortOrder)
       UtilsCookie.setCookie(this, UtilsCookie.cookieIds.sortOrder, this.options.sortOrder)
       UtilsCookie.setCookie(this, UtilsCookie.cookieIds.sortName, this.options.sortName)
       UtilsCookie.setCookie(this, UtilsCookie.cookieIds.sortName, this.options.sortName)
@@ -316,12 +308,12 @@ $.BootstrapTable = class extends $.BootstrapTable {
     super.onMultipleSort(...args)
     super.onMultipleSort(...args)
 
 
     if (this.options.sortPriority === undefined) {
     if (this.options.sortPriority === undefined) {
-      UtilsCookie.deleteCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.sortPriority)
+      UtilsCookie.deleteCookie(this, UtilsCookie.cookieIds.sortPriority)
     } else {
     } else {
       this.options.sortName = undefined
       this.options.sortName = undefined
       this.options.sortOrder = undefined
       this.options.sortOrder = undefined
-      UtilsCookie.deleteCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.sortName)
-      UtilsCookie.deleteCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.sortOrder)
+      UtilsCookie.deleteCookie(this, UtilsCookie.cookieIds.sortName)
+      UtilsCookie.deleteCookie(this, UtilsCookie.cookieIds.sortOrder)
 
 
       UtilsCookie.setCookie(this, UtilsCookie.cookieIds.sortPriority, JSON.stringify(this.options.sortPriority))
       UtilsCookie.setCookie(this, UtilsCookie.cookieIds.sortPriority, JSON.stringify(this.options.sortPriority))
     }
     }
@@ -402,7 +394,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
 
 
   initHeader (...args) {
   initHeader (...args) {
     if (this.options.reorderableColumns && this.options.cookie) {
     if (this.options.reorderableColumns && this.options.cookie) {
-      this.columnsSortOrder = JSON.parse(UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.reorderColumns))
+      this.columnsSortOrder = JSON.parse(UtilsCookie.getCookie(this, UtilsCookie.cookieIds.reorderColumns))
     }
     }
     super.initHeader(...args)
     super.initHeader(...args)
   }
   }
@@ -430,15 +422,15 @@ $.BootstrapTable = class extends $.BootstrapTable {
       return
       return
     }
     }
 
 
-    const sortOrderCookie = UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.sortOrder)
-    const sortOrderNameCookie = UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.sortName)
-    let sortPriorityCookie = UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.sortPriority)
-    const pageNumberCookie = UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.pageNumber)
-    const pageListCookie = UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.pageList)
-    const searchTextCookie = UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.searchText)
-    const cardViewCookie = UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.cardView)
+    const sortOrderCookie = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.sortOrder)
+    const sortOrderNameCookie = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.sortName)
+    let sortPriorityCookie = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.sortPriority)
+    const pageNumberCookie = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.pageNumber)
+    const pageListCookie = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.pageList)
+    const searchTextCookie = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.searchText)
+    const cardViewCookie = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.cardView)
 
 
-    const columnsCookieValue = UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.columns)
+    const columnsCookieValue = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.columns)
 
 
     if (typeof columnsCookieValue === 'boolean' && !columnsCookieValue) {
     if (typeof columnsCookieValue === 'boolean' && !columnsCookieValue) {
       throw new Error('The cookie value of filterBy must be a json!')
       throw new Error('The cookie value of filterBy must be a json!')
@@ -515,7 +507,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
     const cookies = {}
     const cookies = {}
 
 
     $.each(UtilsCookie.cookieIds, (key, value) => {
     $.each(UtilsCookie.cookieIds, (key, value) => {
-      cookies[key] = UtilsCookie.getCookie(bootstrapTable, bootstrapTable.options.cookieIdTable, value)
+      cookies[key] = UtilsCookie.getCookie(bootstrapTable, value)
       if (key === 'columns') {
       if (key === 'columns') {
         cookies[key] = JSON.parse(cookies[key])
         cookies[key] = JSON.parse(cookies[key])
       }
       }

+ 2 - 2
src/extensions/filter-control/bootstrap-table-filter-control.scss

@@ -13,9 +13,9 @@
 }
 }
 
 
 .ms-choice {
 .ms-choice {
-	border: 0;
+  border: 0;
 }
 }
 
 
 .ms-parent > button:focus {
 .ms-parent > button:focus {
-	outline: 0;
+  outline: 0;
 }
 }

+ 0 - 21
src/extensions/pipeline/LICENSE

@@ -1,21 +0,0 @@
-(The MIT License)
-
-Copyright (c) 2019 doug-the-guy <badlydrawnsun@yahoo.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.

+ 0 - 92
src/extensions/pipeline/README.md

@@ -1,92 +0,0 @@
-# Bootstrap Table Pipelining
-
-Use Plugin: [bootstrap-table-pipeline]
-
-This plugin enables client side data caching for server side requests which will
-eliminate the need to issue a new request every page change. This will allow
-for a performance balance for a large data set between returning all data at once
-(client side paging) and a new server side request (server side paging).
-
-There are two new options:
-- usePipeline: enables this feature
-- pipelineSize: the size of each cache window
-
-The size of the pipeline must be evenly divisible by the current page size. This is
-assured by rounding up to the nearest evenly divisible value. For example, if
-the pipeline size is 4990 and the current page size is 25, then pipeline size will
-be dynamically set to 5000.
-
-The cache windows are computed based on the pipeline size and the total number of rows
-returned by the server side query. For example, with pipeline size 500 and total rows
-1300, the cache windows will be:
-
-[{'lower': 0, 'upper': 499}, {'lower': 500, 'upper': 999}, {'lower': 1000, 'upper': 1499}]
-
-Using the limit (i.e. the pipelineSize) and offset parameters, the server side request
-**MUST** return only the data in the requested cache window **AND** the total number of rows.
-To wit, the server side code must use the offset and limit parameters to prepare the response
-data.
-
-On a page change, the new offset is checked if it is within the current cache window. If so,
-the requested page data is returned from the cached data set. Otherwise, a new server side
-request will be issued for the new cache window.
-
-The current cached data is only invalidated on these events:
- - sorting
- - searching
- - page size change
- - page change moves into a new cache window
-
-There are two new events:
-- cached-data-hit.bs.table: issued when cached data is used on a page change
-- cached-data-reset.bs.table: issued when the cached data is invalidated and new server side request is issued
-
-## Features
-
-* Created with Bootstrap 4 
-
-## Usage
-
-```
-# assumed import of bootstrap and bootstrap-table assets
-<script src="/path/to/bootstrap-table-pipeline.js"></script>
-...
-<table id="pipeline_table" 
-    class="table table-striped"
-    data-method='post'
-    data-use-pipeline="true"
-    data-pipeline-size="5000"
-    data-pagination="true"
-    data-side-pagination="server"
-    data-page-size="50">
-    <thead><tr>
-        <th data-field="type" data-sortable="true">Type</th>
-        <th data-field="value" data-sortable="true">Value</th>
-        <th data-field="date" data-sortable="true">Date</th>
-    </tr></thead>
-</table>
-```
-
-## Options
-
-### usePipeline
-
-* type: Boolean
-* description: Set true to enable pipelining
-* default: `false`
-
-## pipelineSize
-
-* type: Integer
-* description: Size of each cache window. Must be greater than 0
-* default: `1000`    
-
-## Events
-
-### onCachedDataHit(cached-data-hit.bs.table)
-
-* Fires when paging was able to use the locally cached data.
-
-### onCachedDataReset(cached-data-reset.bs.table)
-
-* Fires when the locally cached data needed to be reset (i.e. on sorting, searching, page size change or paged out of current cache window)

+ 14 - 15
src/extensions/pipeline/extension.json

@@ -1,18 +1,17 @@
 {
 {
-	"name": "Pipeline",
-	"version": "1.0.0",
-	"description": "Plugin to support a hybrid approach to server/client side paging.",
-	"url": "",
-	"example": "#",
-	
-	"plugins": [{
-		"name": "bootstrap-table-pipeline",
-		"url": ""
-	}],
+    "name": "Pipeline",
+    "version": "1.0.0",
+    "description": "Plugin to support a hybrid approach to server/client side paging.",
+    "url": "",
+    "example": "#",
 
 
-	"author": {
-		"name": "doug-the-guy",
-		"image": ""
-	}
-}
+    "plugins": [{
+        "name": "bootstrap-table-pipeline",
+        "url": ""
+    }],
 
 
+    "author": {
+        "name": "doug-the-guy",
+        "image": ""
+    }
+}