From 47df0b296b282d0fe554c3b596b366c5403c9588 Mon Sep 17 00:00:00 2001
From: Azul <azul@riseup.net>
Date: Tue, 17 Oct 2017 14:05:59 +0200
Subject: [PATCH] feat: sort invite codes by last update

They used to be sorted by the code which was not helpful

fixes #8806
requires deploy of new design docs to the platform
---
 app/controllers/invite_codes_controller.rb    | 4 +++-
 app/models/invite_code.rb                     | 2 ++
 app/views/invite_codes/_invite_code.html.haml | 2 ++
 app/views/invite_codes/index.html.haml        | 4 ++--
 4 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/app/controllers/invite_codes_controller.rb b/app/controllers/invite_codes_controller.rb
index 6a7fef3c..96836eea 100644
--- a/app/controllers/invite_codes_controller.rb
+++ b/app/controllers/invite_codes_controller.rb
@@ -7,7 +7,9 @@ class InviteCodesController < ApplicationController
 
   def index
     @invite  = InviteCode.new # for the creation form.
-    @invites = InviteCode.all.page(params[:page]).per(APP_CONFIG[:pagination_size])
+    @invites = InviteCode.by_updated_at.descending.
+      page(params[:page]).
+      per(APP_CONFIG[:pagination_size])
     respond_with @invites
   end
 
diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb
index 9c6df660..8a564842 100644
--- a/app/models/invite_code.rb
+++ b/app/models/invite_code.rb
@@ -12,6 +12,8 @@ class InviteCode < CouchRest::Model::Base
   design do
     view :by_invite_code
     view :by_invite_count
+    view :by_created_at
+    view :by_updated_at
   end
 
   def initialize(attributes = {}, options = {})
diff --git a/app/views/invite_codes/_invite_code.html.haml b/app/views/invite_codes/_invite_code.html.haml
index a3c420d2..a167432d 100644
--- a/app/views/invite_codes/_invite_code.html.haml
+++ b/app/views/invite_codes/_invite_code.html.haml
@@ -1,4 +1,6 @@
 %tr
+  %td
+    = simple_date(invite_code.updated_at)
   %td
     = simple_date(invite_code.created_at)
   %td
diff --git a/app/views/invite_codes/index.html.haml b/app/views/invite_codes/index.html.haml
index 40fccdf3..98c49c78 100644
--- a/app/views/invite_codes/index.html.haml
+++ b/app/views/invite_codes/index.html.haml
@@ -11,10 +11,10 @@
       %td= f.text_field :max_uses, style: 'width: 4em'
       %td= f.submit t("helpers.submit.invites.create"), style: 'margin-bottom: 10px', class: 'btn btn-default'
 
-= table @invites, %w(created code uses actions)
+= table @invites, %w(updated created code uses actions)
 
 -# select the text of the invite code when you click on it:
 :javascript
   $("input.invite-code").focus(function(){
     this.select();
-  });
\ No newline at end of file
+  });
-- 
GitLab