Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/local/bin/python
2# encoding: utf-8
3"""
4*The sort dropdown used to sort the tickets displayed in the marshall*
6:Author:
7 David Young
8"""
9import sys
10import os
11import re
12import khufu
14def ticket_table_sorting_dropdown(
15 log,
16 request,
17 sortBy=False,
18 sortDesc=False
19):
20 """ticket_table_sorting_dropdown
22 **Key Arguments**
24 - ``log`` -- the logger
25 - ``request`` -- the request
26 - ``sortBy`` -- the incoming sortBy
27 - ``sortDesc`` -- incoming sort direction
30 **Return**
32 - ``sortDropdown`` -- the sort dropdown for the transient listing pages
34 """
35 routename = request.matched_route.name
36 if "elementId" in request.matchdict:
37 elementId = request.matchdict["elementId"]
38 else:
39 elementId = False
41 theseParams = dict(request.params)
42 alist = ["sortBy", "sortDesc"]
43 for i in alist:
44 if i in theseParams:
45 del theseParams[i]
47 # GENERATE THE SORT OPTION LIST
48 optionList = [
49 "ra",
50 "dec",
51 "name",
52 "date added to marshall",
53 "date of last observation",
54 "discovery date",
55 "pre-discovery non-detection date",
56 "absolute peak magnitude",
57 "spectral type",
58 "classification date",
59 "redshift",
60 "latest comment date",
61 "current magnitude",
62 "pi",
63 "priority",
64 "galactic latitude",
65 "contextual classification",
66 "association separation"
67 ]
69 # remove options not available for inbox items
70 if "mwl" not in theseParams or theseParams["mwl"] == "inbox":
71 optionList.remove("classification date")
72 optionList.remove("spectral type")
73 optionList.remove("pi")
75 if "mwl" not in theseParams or theseParams["mwl"] not in ["pending observation", "allObsQueue", "following"]:
76 optionList.remove("priority")
78 dbSortBy = sortBy
79 if sortBy == "raDeg":
80 sortBy = "ra"
81 if sortBy == "decDeg":
82 sortBy = "dec"
83 if sortBy == "masterName":
84 sortBy = "name"
85 if sortBy == "dateAdded":
86 sortBy = "date added to marshall"
87 if sortBy == "currentMagnitudeDate":
88 sortBy = "date of last observation"
89 if sortBy == "earliestDetection":
90 sortBy = "discovery date"
91 if sortBy == "lastNonDetectionDate":
92 sortBy = "pre-discovery non-detection date"
93 if sortBy == "absolutePeakMagnitude":
94 sortBy = "absolute peak magnitude"
95 if sortBy == "spectralType" or sortBy == "recentClassification":
96 sortBy = "spectral type"
97 if sortBy == "classificationDate":
98 sortBy = "classification date"
99 if sortBy == "redshift":
100 sortBy = "redshift"
101 if sortBy == "latestComment":
102 sortBy = "latest comment date"
103 if sortBy == "currentMagnitude":
104 sortBy = "current magnitude"
105 if sortBy == "pi_name":
106 sortBy = "pi"
107 if sortBy == "observationPriority":
108 sortBy = "priority"
109 if sortBy == "glat":
110 sortBy = "galactic latitude"
111 if sortBy == "sherlockClassification":
112 sortBy = "contextual classification"
113 if sortBy == "separationArcsec":
114 sortBy = "association separation"
116 optionList = sorted(optionList)
117 if sortBy:
118 try:
119 optionList.remove(sortBy)
120 except:
121 pass
123 # ADD LINKS TO OPTIONS
124 linkList = []
125 for option in optionList:
126 if option == "ra":
127 dbOption = "raDeg"
128 if option == "dec":
129 dbOption = "decDeg"
130 if option == "name":
131 dbOption = "masterName"
132 if option == "date added to marshall":
133 dbOption = "dateAdded"
134 if option == "date of last observation":
135 dbOption = "currentMagnitudeDate"
136 if option == "discovery date":
137 dbOption = "earliestDetection"
138 if option == "pre-discovery non-detection date":
139 dbOption = "lastNonDetectionDate"
140 if option == "absolute peak magnitude":
141 dbOption = "absolutePeakMagnitude"
142 if option == "spectral type":
143 dbOption = "recentClassification"
144 if option == "classification date":
145 dbOption = "classificationDate"
146 if option == "redshift":
147 dbOption = "redshift"
148 if option == "latest comment date":
149 dbOption = "latestComment"
150 if option == "current magnitude":
151 dbOption = "currentMagnitude"
152 if option == "pi":
153 dbOption = "pi_name"
154 if option == "priority":
155 dbOption = "observationPriority"
156 if option == "galactic latitude":
157 dbOption = "glat"
158 if option == "contextual classification":
159 dbOption = "sherlockClassification"
160 if option == "association separation":
161 dbOption = "separationArcsec"
163 theseParams["sortBy"] = dbOption
164 theseParams["sortDesc"] = False
166 thisLink = request.route_path(
167 routename, elementId=elementId, _query=theseParams)
168 thisLink = khufu.a(
169 content=option,
170 href=thisLink,
171 )
172 thisLink = khufu.li(
173 content=thisLink, # if a subMenu for dropdown this should be <ul>
174 )
175 linkList.append(thisLink)
177 # SET SORT ARROW DIRECTION
178 if sortDesc != "True":
179 arrow = """<i class="icon-arrow-down4"></i>"""
180 theseParams["sortBy"] = dbSortBy
181 theseParams["sortDesc"] = True
182 topButtonLink = request.route_path(
183 routename, elementId=elementId, _query=theseParams)
184 else:
185 arrow = """<i class="icon-arrow-up4"></i>"""
186 theseParams["sortBy"] = dbSortBy
187 theseParams["sortDesc"] = False
188 topButtonLink = request.route_path(
189 routename, elementId=elementId, _query=theseParams)
191 # ADD TEXT COLOR
192 arrow = khufu.coloredText(
193 text=arrow,
194 color="red",
195 size=False, # 1-10
196 pull=False, # "left" | "right"
197 )
199 if sortBy == "ra":
200 dbSortBy = "raDeg"
201 if sortBy == "dec":
202 dbSortBy = "decDeg"
203 if sortBy == "name":
204 dbSortBy = "masterName"
205 if sortBy == "date added to marshall":
206 dbSortBy = "dateAdded"
207 if option == "date of last observation":
208 dbSortBy = "currentMagnitudeDate"
209 if sortBy == "discovery date":
210 dbSortBy = "earliestDetection"
211 if sortBy == "pre-discovery non-detection date":
212 dbSortBy = "lastNonDetectionDate"
213 if sortBy == "absolute peak magnitude":
214 dbSortBy = "absolutePeakMagnitude"
215 if sortBy == "spectral type":
216 dbSortBy = "spectralType"
217 if sortBy == "classification date":
218 dbSortBy = "classificationDate"
219 if sortBy == "redshift":
220 dbSortBy = "redshift"
221 if sortBy == "latest comment date":
222 dbSortBy = "latestComment"
223 if sortBy == "current magnitude":
224 dbSortBy = "currentMagnitude"
225 if sortBy == "galactic latitude":
226 dbSortBy = "glat"
227 if sortBy == "contextual classification":
228 dbSortBy = "sherlockClassification"
229 if sortBy == "association separation":
230 dbSortBy = "separationArcsec"
232 popover = khufu.popover(
233 tooltip=True,
234 placement="left", # [ top | bottom | left | right ]
235 trigger="hover", # [ False | click | hover | focus | manual ]
236 title="click to reserve sort or select dropdown to change sort attribute",
237 content=False,
238 delay=20
239 )
241 sortDropdown = khufu.dropdown(
242 buttonSize='default',
243 buttonColor='default', # [ default | sucess | error | warning | info ]
244 menuTitle=" %(arrow)s %(sortBy)s" % locals(),
245 splitButton=True,
246 splitButtonHref=topButtonLink,
247 linkList=linkList,
248 separatedLinkList=False,
249 pull=False,
250 # use javascript to explode contained links
251 htmlClass=False,
252 direction='down', # [ down | up ]
253 onPhone=True,
254 onTablet=True,
255 onDesktop=True,
256 popover=popover
257 )
259 return sortDropdown