func updateComplaintHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) { cdb := complaintdb.NewDB(ctx) sesh, _ := GetUserSession(ctx) new := form2Complaint(r) newFlightNumber := r.FormValue("manualflightnumber") newTimeString := r.FormValue("manualtimestring") if orig, err := cdb.GetComplaintByKey(new.DatastoreKey, sesh.Email); err != nil { cdb.Errorf("updateform, getComplaint: %v", err) http.Error(w, err.Error(), http.StatusInternalServerError) } else { // Overlay our new values orig.Description = new.Description orig.Loudness = new.Loudness orig.Activity = new.Activity orig.HeardSpeedbreaks = new.HeardSpeedbreaks // If we're manually changing a flightnumber, wipe out all the other flight data if newFlightNumber != orig.AircraftOverhead.FlightNumber { orig.AircraftOverhead = flightid.Aircraft{FlightNumber: newFlightNumber} } // Compose a new timestamp, by inserting hew HH:MM:SS fragment into the old timestamp (date+nanoseconds) newTimestamp, err2 := date.ParseInPdt("2006.01.02 .999999999 15:04:05", orig.Timestamp.Format("2006.01.02 .999999999 ")+newTimeString) if err2 != nil { http.Error(w, err2.Error(), http.StatusInternalServerError) } orig.Timestamp = newTimestamp err := cdb.UpdateComplaint(*orig, sesh.Email) if err != nil { cdb.Errorf("cdb.UpdateComplaint failed: %v", err) http.Error(w, err.Error(), http.StatusInternalServerError) return } } http.Redirect(w, r, "/", http.StatusFound) }
func queryHandler(w http.ResponseWriter, r *http.Request) { if r.FormValue("date") == "" && r.FormValue("epoch") == "" { var params = map[string]interface{}{ "TwoHoursAgo": date.NowInPdt().Add(-2 * time.Hour), } if err := templates.ExecuteTemplate(w, "fdb-queryform", params); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } return } db := fdb.NewDB(r) db.Memcache = true var t time.Time if r.FormValue("epoch") != "" { if epoch, err := strconv.ParseInt(r.FormValue("epoch"), 10, 64); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } else { t = time.Unix(epoch, 0) } } else { var err2 error t, err2 = date.ParseInPdt("2006/01/02 15:04:05", r.FormValue("date")+" "+r.FormValue("time")) if err2 != nil { http.Error(w, err2.Error(), http.StatusInternalServerError) return } } var refPoint *geo.Latlong = nil if r.FormValue("lat") != "" { refPoint = &geo.Latlong{} var err error if refPoint.Lat, err = strconv.ParseFloat(r.FormValue("lat"), 64); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } if refPoint.Long, err = strconv.ParseFloat(r.FormValue("long"), 64); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } } if snapshots, err := db.LookupSnapshotsAtTimestampUTC(t.UTC(), refPoint, 1000); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } else { var params = map[string]interface{}{ "Legend": buildLegend(t), "SearchTimeUTC": t.UTC(), "SearchTime": date.InPdt(t), "Flights": snapshots2params(snapshots), "FlightsJS": ftype.FlightSnapshotSet(snapshots).ToJSVar(), "MapsAPIKey": kGoogleMapsAPIKey, "Center": sfo.KLatlongSERFR1, "Zoom": 9, // "CaptureArea": fdb.KBoxSnarfingCatchment, // comment out, as we don't want it in this view } if r.FormValue("resultformat") == "json" { for i, _ := range snapshots { snapshots[i].F.Track = nil snapshots[i].F.Tracks = nil } js, err := json.Marshal(snapshots) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") w.Write(js) } else { templateName := "fdb-queryresults-map" if r.FormValue("resultformat") == "list" { templateName = "fdb-queryresults-list" } if err := templates.ExecuteTemplate(w, templateName, params); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } } } }