Sort working
Former-commit-id: 82fb8c7c1e2fe754e7da9a26a800a7814e562033 [formerly 4bca5432790eef9a06bda1a3779b060c0ee8717c] [formerly 2dd333885a261827f95692a8d68dfdf81f81a303 [formerly ce6557997ab17440253e8649b7c0209942475a4b]] Former-commit-id: cfbf8f1a49e5cde20ec71edd1d61389bd1f820c6 [formerly 94762c33a82b2b1a8fbd1c1969dc8d0f4dfce1d5] Former-commit-id: 623a70bda4ea4b7a821ca756234addcb97dfb1c3
This commit is contained in:
		
							parent
							
								
									869cd562e7
								
							
						
					
					
						commit
						c3b882aee5
					
				| 
						 | 
				
			
			@ -8,14 +8,14 @@
 | 
			
		|||
      <div class="item header">
 | 
			
		||||
        <div></div>
 | 
			
		||||
        <div>
 | 
			
		||||
          <p v-bind:class="{ active: req.sort === 'name' }" class="name"><span>Name</span>
 | 
			
		||||
            <a v-if="req.sort === 'name' && req.order != 'asc'" href="?sort=name&order=asc"><i class="material-icons">arrow_upward</i></a>
 | 
			
		||||
            <a v-else href="?sort=name&order=desc"><i class="material-icons">arrow_downward</i></a>
 | 
			
		||||
          <p :class="{ active: nameSorted }" class="name" @click="sort('name')">
 | 
			
		||||
            <span>Name</span>
 | 
			
		||||
            <i class="material-icons">{{ nameIcon }}</i>
 | 
			
		||||
          </p>
 | 
			
		||||
 | 
			
		||||
          <p v-bind:class="{ active: req.sort === 'size' }" class="size"><span>Size</span>
 | 
			
		||||
            <a v-if="req.sort === 'size' && req.order != 'asc'" href="?sort=size&order=asc"><i class="material-icons">arrow_upward</i></a>
 | 
			
		||||
            <a v-else href="?sort=size&order=desc"><i class="material-icons">arrow_downward</i></a>
 | 
			
		||||
          <p :class="{ active: !nameSorted }" class="size" @click="sort('size')">
 | 
			
		||||
            <span>Size</span>
 | 
			
		||||
            <i class="material-icons">{{ sizeIcon }}</i>
 | 
			
		||||
          </p>
 | 
			
		||||
 | 
			
		||||
          <p class="modified">Last modified</p>
 | 
			
		||||
| 
						 | 
				
			
			@ -74,7 +74,29 @@ import api from '@/utils/api'
 | 
			
		|||
export default {
 | 
			
		||||
  name: 'listing',
 | 
			
		||||
  components: { Item },
 | 
			
		||||
  computed: mapState(['req']),
 | 
			
		||||
  computed: {
 | 
			
		||||
    ...mapState(['req']),
 | 
			
		||||
    nameSorted () {
 | 
			
		||||
      return (this.req.sort === 'name')
 | 
			
		||||
    },
 | 
			
		||||
    ascOrdered () {
 | 
			
		||||
      return (this.req.order === 'asc')
 | 
			
		||||
    },
 | 
			
		||||
    nameIcon () {
 | 
			
		||||
      if (this.nameSorted && !this.ascOrdered) {
 | 
			
		||||
        return 'arrow_upward'
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      return 'arrow_downward'
 | 
			
		||||
    },
 | 
			
		||||
    sizeIcon () {
 | 
			
		||||
      if (!this.nameSorted && this.ascOrdered) {
 | 
			
		||||
        return 'arrow_downward'
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      return 'arrow_upward'
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  mounted: function () {
 | 
			
		||||
    document.addEventListener('dragover', function (event) {
 | 
			
		||||
      event.preventDefault()
 | 
			
		||||
| 
						 | 
				
			
			@ -151,6 +173,23 @@ export default {
 | 
			
		|||
        })
 | 
			
		||||
 | 
			
		||||
      return false
 | 
			
		||||
    },
 | 
			
		||||
    sort (sort) {
 | 
			
		||||
      let order = 'desc'
 | 
			
		||||
 | 
			
		||||
      if (sort === 'name') {
 | 
			
		||||
        if (this.nameIcon === 'arrow_upward') {
 | 
			
		||||
          order = 'asc'
 | 
			
		||||
        }
 | 
			
		||||
      } else {
 | 
			
		||||
        if (this.sizeIcon === 'arrow_upward') {
 | 
			
		||||
          order = 'asc'
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      document.cookie = `sort=${sort}; max-age=31536000; path=${this.$store.state.baseURL}`
 | 
			
		||||
      document.cookie = `order=${order}; max-age=31536000; path=${this.$store.state.baseURL}`
 | 
			
		||||
      this.$store.commit('setReload', true)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								api.go
								
								
								
								
							
							
						
						
									
										2
									
								
								api.go
								
								
								
								
							| 
						 | 
				
			
			@ -268,7 +268,7 @@ func handleSortOrder(w http.ResponseWriter, r *http.Request, scope string) (sort
 | 
			
		|||
		if sortCookie, sortErr := r.Cookie("sort"); sortErr == nil {
 | 
			
		||||
			sort = sortCookie.Value
 | 
			
		||||
		}
 | 
			
		||||
	case "name", "size", "type":
 | 
			
		||||
	case "name", "size":
 | 
			
		||||
		http.SetCookie(w, &http.Cookie{
 | 
			
		||||
			Name:   "sort",
 | 
			
		||||
			Value:  sort,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										16
									
								
								file.go
								
								
								
								
							
							
						
						
									
										16
									
								
								file.go
								
								
								
								
							| 
						 | 
				
			
			@ -313,8 +313,6 @@ func (l listing) ApplySort() {
 | 
			
		|||
			sort.Sort(sort.Reverse(byName(l)))
 | 
			
		||||
		case "size":
 | 
			
		||||
			sort.Sort(sort.Reverse(bySize(l)))
 | 
			
		||||
		case "time":
 | 
			
		||||
			sort.Sort(sort.Reverse(byTime(l)))
 | 
			
		||||
		default:
 | 
			
		||||
			// If not one of the above, do nothing
 | 
			
		||||
			return
 | 
			
		||||
| 
						 | 
				
			
			@ -325,8 +323,6 @@ func (l listing) ApplySort() {
 | 
			
		|||
			sort.Sort(byName(l))
 | 
			
		||||
		case "size":
 | 
			
		||||
			sort.Sort(bySize(l))
 | 
			
		||||
		case "time":
 | 
			
		||||
			sort.Sort(byTime(l))
 | 
			
		||||
		default:
 | 
			
		||||
			sort.Sort(byName(l))
 | 
			
		||||
			return
 | 
			
		||||
| 
						 | 
				
			
			@ -337,7 +333,6 @@ func (l listing) ApplySort() {
 | 
			
		|||
// Implement sorting for listing
 | 
			
		||||
type byName listing
 | 
			
		||||
type bySize listing
 | 
			
		||||
type byTime listing
 | 
			
		||||
 | 
			
		||||
// By Name
 | 
			
		||||
func (l byName) Len() int {
 | 
			
		||||
| 
						 | 
				
			
			@ -382,17 +377,6 @@ func (l bySize) Less(i, j int) bool {
 | 
			
		|||
	return iSize < jSize
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// By Time
 | 
			
		||||
func (l byTime) Len() int {
 | 
			
		||||
	return len(l.Items)
 | 
			
		||||
}
 | 
			
		||||
func (l byTime) Swap(i, j int) {
 | 
			
		||||
	l.Items[i], l.Items[j] = l.Items[j], l.Items[i]
 | 
			
		||||
}
 | 
			
		||||
func (l byTime) Less(i, j int) bool {
 | 
			
		||||
	return l.Items[i].ModTime.Before(l.Items[j].ModTime)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var textExtensions = [...]string{
 | 
			
		||||
	".md", ".markdown", ".mdown", ".mmark",
 | 
			
		||||
	".asciidoc", ".adoc", ".ad",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue