Skip to content

Commit

Permalink
timezone fix - service tabs - statup app updates
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterlong committed Nov 29, 2018
1 parent f27222d commit c4b1a53
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 46 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ databases:
#
# Download and Install dependencies
#

# run dep to install all required golang dependecies
dep:
dep ensure -vendor-only
Expand Down
7 changes: 7 additions & 0 deletions core/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,13 @@ func (s *Service) Update(restart bool) error {
utils.Log(3, fmt.Sprintf("Failed to update service %v. %v", s.Name, err))
return err.Error
}
// clear the notification queue for a service
if !s.AllowNotifications.Bool {
for _, n := range CoreApp.Notifications {
notif := n.(*notifier.Notification)
notif.ResetUniqueQueue(s.Id)
}
}
if restart {
s.Close()
s.Start()
Expand Down
3 changes: 3 additions & 0 deletions handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ var handlerFuncs = func(w http.ResponseWriter, r *http.Request) template.FuncMap
"safe": func(html string) template.HTML {
return template.HTML(html)
},
"safeURL": func(u string) template.URL {
return template.URL(u)
},
"Auth": func() bool {
return IsAuthenticated(r)
},
Expand Down
11 changes: 8 additions & 3 deletions handlers/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package handlers
import (
"encoding/json"
"errors"
"fmt"
"github.com/gorilla/mux"
"github.com/hunterlong/statup/core"
"github.com/hunterlong/statup/types"
Expand Down Expand Up @@ -66,12 +67,17 @@ func reorderServiceHandler(w http.ResponseWriter, r *http.Request) {
}
var newOrder []*serviceOrder
decoder := json.NewDecoder(r.Body)
decoder.Decode(&newOrder)
if err := decoder.Decode(&newOrder); err != nil {
utils.Log(3, fmt.Sprint("error decoding reordering services: %v", err.Error()))
}
for _, s := range newOrder {
service := core.SelectService(s.Id)
service.Order = s.Order
service.Update(false)
if err := service.Update(false); err != nil {
utils.Log(3, fmt.Sprint("error reordering services: %v", err.Error()))
}
}
w.Write([]byte("ok"))
w.WriteHeader(http.StatusOK)
}

Expand Down Expand Up @@ -172,7 +178,6 @@ func apiServiceUpdateHandler(w http.ResponseWriter, r *http.Request) {
return
}
go service.Check(true)

sendJsonAction(service, "update", w, r)
}

Expand Down
10 changes: 9 additions & 1 deletion handlers/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package handlers

import (
"fmt"
"github.com/gorilla/mux"
"github.com/hunterlong/statup/core"
"github.com/hunterlong/statup/source"
Expand All @@ -39,6 +40,7 @@ func saveSettingsHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusSeeOther)
return
}
var err error
r.ParseForm()
app := core.CoreApp
name := r.PostForm.Get("project")
Expand All @@ -65,8 +67,14 @@ func saveSettingsHandler(w http.ResponseWriter, r *http.Request) {
timeFloat, _ := strconv.ParseFloat(timezone, 10)
app.Timezone = float32(timeFloat)

utils.Log(1, fmt.Sprintf("timezone: %v", timezone))
utils.Log(1, fmt.Sprintf("tzone: %f", app.Timezone))

app.UseCdn = types.NewNullBool(r.PostForm.Get("enable_cdn") == "on")
core.CoreApp, _ = core.UpdateCore(app)
core.CoreApp, err = core.UpdateCore(app)
if err != nil {
utils.Log(3, fmt.Sprintf("issue updating Core: %v", err.Error()))
}
//notifiers.OnSettingsSaved(core.CoreApp.ToCore())
ExecuteResponse(w, r, "settings.html", core.CoreApp, "/settings")
}
Expand Down
7 changes: 2 additions & 5 deletions source/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,10 @@ $('form.ajax_form').on('submit', function() {
let alerter = form.find('#alerter');
var arrayData = [];
let newArr = {};
console.log(values);
Spinner(button);
values.forEach(function(k, v) {
if (k.name === "password_confirm") {
return
}
if (k.value === "") {
if (k.name === "password_confirm" || k.value === "") {
return
}
if (k.value === "on") {
Expand Down Expand Up @@ -231,7 +229,6 @@ $('form.ajax_form').on('submit', function() {
});

function CreateService(output) {
console.log('creating service', output)
let form = output.form;
let data = output.data.output;
let objTbl = `<tr id="service_${data.id}">
Expand Down
8 changes: 4 additions & 4 deletions source/tmpl/service.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ <h3>{{.Title}}</h3>

{{if Auth}}
<nav class="nav nav-pills flex-column flex-sm-row mt-3" id="service_tabs" role="serviceLists">
<a class="flex-sm-fill text-sm-center nav-link active" id="failures-tab" data-toggle="tab" href="#failures" role="tab" aria-controls="failures" aria-selected="true">Failures</a>
<a class="flex-sm-fill text-sm-center nav-link active" id="edit-tab" data-toggle="tab" href="#edit" role="tab" aria-controls="edit" aria-selected="false">Edit Service</a>
<a class="flex-sm-fill text-sm-center nav-link" id="failures-tab" data-toggle="tab" href="#failures" role="tab" aria-controls="failures" aria-selected="true">Failures</a>
<a class="flex-sm-fill text-sm-center nav-link" id="checkins-tab" data-toggle="tab" href="#checkins" role="tab" aria-controls="checkins" aria-selected="false">Checkins</a>
<a class="flex-sm-fill text-sm-center nav-link" id="response-tab" data-toggle="tab" href="#response" role="tab" aria-controls="response" aria-selected="false">Response</a>
<a class="flex-sm-fill text-sm-center nav-link" id="edit-tab" data-toggle="tab" href="#edit" role="tab" aria-controls="edit" aria-selected="false">Edit Service</a>
</nav>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="failures" role="serviceLists" aria-labelledby="failures-tab">
<div class="tab-pane fade" id="failures" role="serviceLists" aria-labelledby="failures-tab">
{{$failures := $s.LimitedFailures 16}}
{{ if $failures }}
<div class="list-group mt-3 mb-4">
Expand Down Expand Up @@ -164,7 +164,7 @@ <h3>Last Response</h3>
</div>
</div>
</div>
<div class="tab-pane fade" id="edit" role="serviceLists" aria-labelledby="edit-tab">
<div class="tab-pane fade show active" id="edit" role="serviceLists" aria-labelledby="edit-tab">
{{template "form_service" $s}}
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions source/tmpl/services.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ <h3>Create Service</h3>
var o = {service: parseInt(dId), order: i};
newOrder.push(o);
});
console.log(JSON.stringify(newOrder));
$.post("/services/reorder", JSON.stringify(newOrder), function(data, status){
});
});
Expand Down
63 changes: 32 additions & 31 deletions source/tmpl/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,37 @@ <h3>Settings</h3>
<div class="form-group">
<label for="timezone">Timezone</label><span class="mt-1 small float-right">Current: {{.CurrentTime}}</span>
<select class="form-control" name="timezone" id="timezone">
<option value="-12.0" {{if eq (ToString .Timezone) "-12"}}selected{{end}}>(GMT -12:00) Eniwetok, Kwajalein</option>
<option value="-11.0" {{if eq (ToString .Timezone) "-11"}}selected{{end}}>(GMT -11:00) Midway Island, Samoa</option>
<option value="-10.0" {{if eq (ToString .Timezone) "-10"}}selected{{end}}>(GMT -10:00) Hawaii</option>
<option value="-9.0" {{if eq (ToString .Timezone) "-9"}}selected{{end}}>(GMT -9:00) Alaska</option>
<option value="-8.0" {{if eq (ToString .Timezone) "-8"}}selected{{end}}>(GMT -8:00) Pacific Time (US &amp; Canada)</option>
<option value="-7.0" {{if eq (ToString .Timezone) "-7"}}selected{{end}}>(GMT -7:00) Mountain Time (US &amp; Canada)</option>
<option value="-6.0" {{if eq (ToString .Timezone) "-6"}}selected{{end}}>(GMT -6:00) Central Time (US &amp; Canada), Mexico City</option>
<option value="-5.0" {{if eq (ToString .Timezone) "-5"}}selected{{end}}>(GMT -5:00) Eastern Time (US &amp; Canada), Bogota, Lima</option>
<option value="-4.0" {{if eq (ToString .Timezone) "-4"}}selected{{end}}>(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz</option>
<option value="-3.5" {{if eq (ToString .Timezone) "-3.5"}}selected{{end}}>(GMT -3:30) Newfoundland</option>
<option value="-3.0" {{if eq (ToString .Timezone) "-3"}}selected{{end}}>(GMT -3:00) Brazil, Buenos Aires, Georgetown</option>
<option value="-2.0" {{if eq (ToString .Timezone) "-2"}}selected{{end}}>(GMT -2:00) Mid-Atlantic</option>
<option value="-1.0" {{if eq (ToString .Timezone) "-1"}}selected{{end}}>(GMT -1:00 hour) Azores, Cape Verde Islands</option>
<option value="0.0" {{if eq (ToString .Timezone) "0"}}selected{{end}}>(GMT) Western Europe Time, London, Lisbon, Casablanca</option>
<option value="1.0" {{if eq (ToString .Timezone) "1"}}selected{{end}}>(GMT +1:00 hour) Brussels, Copenhagen, Madrid, Paris</option>
<option value="2.0" {{if eq (ToString .Timezone) "2"}}selected{{end}}>(GMT +2:00) Kaliningrad, South Africa</option>
<option value="3.0" {{if eq (ToString .Timezone) "3"}}selected{{end}}>(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg</option>
<option value="3.5" {{if eq (ToString .Timezone) "3.5"}}selected{{end}}>(GMT +3:30) Tehran</option>
<option value="4.0" {{if eq (ToString .Timezone) "4"}}selected{{end}}>(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi</option>
<option value="4.5" {{if eq (ToString .Timezone) "4.5"}}selected{{end}}>(GMT +4:30) Kabul</option>
<option value="5.0" {{if eq (ToString .Timezone) "5"}}selected{{end}}>(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent</option>
<option value="5.5" {{if eq (ToString .Timezone) "5.5"}}selected{{end}}>(GMT +5:30) Bombay, Calcutta, Madras, New Delhi</option>
<option value="5.75" {{if eq (ToString .Timezone) "5.75"}}selected{{end}}>(GMT +5:45) Kathmandu</option>
<option value="6.0" {{if eq (ToString .Timezone) "6"}}selected{{end}}>(GMT +6:00) Almaty, Dhaka, Colombo</option>
<option value="7.0" {{if eq (ToString .Timezone) "7"}}selected{{end}}>(GMT +7:00) Bangkok, Hanoi, Jakarta</option>
<option value="8.0" {{if eq (ToString .Timezone) "8"}}selected{{end}}>(GMT +8:00) Beijing, Perth, Singapore, Hong Kong</option>
<option value="9.0" {{if eq (ToString .Timezone) "9"}}selected{{end}}>(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk</option>
<option value="9.5" {{if eq (ToString .Timezone) "9.5"}}selected{{end}}>(GMT +9:30) Adelaide, Darwin</option>
<option value="10.0" {{if eq (ToString .Timezone) "10.5"}}selected{{end}}>(GMT +10:00) Eastern Australia, Guam, Vladivostok</option>
<option value="11.0" {{if eq (ToString .Timezone) "11"}}selected{{end}}>(GMT +11:00) Magadan, Solomon Islands, New Caledonia</option>
<option value="12.0" {{if eq (ToString .Timezone) "12"}}selected{{end}}>(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka</option>
<option value="-12.0" {{if eq (ToString .Timezone) "-12.000000"}}selected{{end}}>(GMT -12:00) Eniwetok, Kwajalein</option>
<option value="-11.0" {{if eq (ToString .Timezone) "-11.000000"}}selected{{end}}>(GMT -11:00) Midway Island, Samoa</option>
<option value="-10.0" {{if eq (ToString .Timezone) "-10.000000"}}selected{{end}}>(GMT -10:00) Hawaii</option>
<option value="-9.0" {{if eq (ToString .Timezone) "-9.000000"}}selected{{end}}>(GMT -9:00) Alaska</option>
<option value="-8.0" {{if eq (ToString .Timezone) "-8.000000"}}selected{{end}}>(GMT -8:00) Pacific Time (US &amp; Canada)</option>
<option value="-7.0" {{if eq (ToString .Timezone) "-7.000000"}}selected{{end}}>(GMT -7:00) Mountain Time (US &amp; Canada)</option>
<option value="-6.0" {{if eq (ToString .Timezone) "-6.000000"}}selected{{end}}>(GMT -6:00) Central Time (US &amp; Canada), Mexico City</option>
<option value="-5.0" {{if eq (ToString .Timezone) "-5.000000"}}selected{{end}}>(GMT -5:00) Eastern Time (US &amp; Canada), Bogota, Lima</option>
<option value="-4.0" {{if eq (ToString .Timezone) "-4.000000"}}selected{{end}}>(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz</option>
<option value="-3.5" {{if eq (ToString .Timezone) "-3.500000"}}selected{{end}}>(GMT -3:30) Newfoundland</option>
<option value="-3.0" {{if eq (ToString .Timezone) "-3.000000"}}selected{{end}}>(GMT -3:00) Brazil, Buenos Aires, Georgetown</option>
<option value="-2.0" {{if eq (ToString .Timezone) "-2.000000"}}selected{{end}}>(GMT -2:00) Mid-Atlantic</option>
<option value="-1.0" {{if eq (ToString .Timezone) "-1.000000"}}selected{{end}}>(GMT -1:00 hour) Azores, Cape Verde Islands</option>
<option value="0.0" {{if eq (ToString .Timezone) "0.000000"}}selected{{end}}>(GMT) Western Europe Time, London, Lisbon, Casablanca</option>
<option value="1.0" {{if eq (ToString .Timezone) "1.000000"}}selected{{end}}>(GMT +1:00 hour) Brussels, Copenhagen, Madrid, Paris</option>
<option value="2.0" {{if eq (ToString .Timezone) "2.000000"}}selected{{end}}>(GMT +2:00) Kaliningrad, South Africa</option>
<option value="3.0" {{if eq (ToString .Timezone) "3.000000"}}selected{{end}}>(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg</option>
<option value="3.5" {{if eq (ToString .Timezone) "3.500000"}}selected{{end}}>(GMT +3:30) Tehran</option>
<option value="4.0" {{if eq (ToString .Timezone) "4.000000"}}selected{{end}}>(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi</option>
<option value="4.5" {{if eq (ToString .Timezone) "4.500000"}}selected{{end}}>(GMT +4:30) Kabul</option>
<option value="5.0" {{if eq (ToString .Timezone) "5.000000"}}selected{{end}}>(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent</option>
<option value="5.5" {{if eq (ToString .Timezone) "5.500000"}}selected{{end}}>(GMT +5:30) Bombay, Calcutta, Madras, New Delhi</option>
<option value="5.75" {{if eq (ToString .Timezone) "5.750000"}}selected{{end}}>(GMT +5:45) Kathmandu</option>
<option value="6.0" {{if eq (ToString .Timezone) "6.000000"}}selected{{end}}>(GMT +6:00) Almaty, Dhaka, Colombo</option>
<option value="7.0" {{if eq (ToString .Timezone) "7.000000"}}selected{{end}}>(GMT +7:00) Bangkok, Hanoi, Jakarta</option>
<option value="8.0" {{if eq (ToString .Timezone) "8.000000"}}selected{{end}}>(GMT +8:00) Beijing, Perth, Singapore, Hong Kong</option>
<option value="9.0" {{if eq (ToString .Timezone) "9.000000"}}selected{{end}}>(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk</option>
<option value="9.5" {{if eq (ToString .Timezone) "9.500000"}}selected{{end}}>(GMT +9:30) Adelaide, Darwin</option>
<option value="10.0" {{if eq (ToString .Timezone) "10.500000"}}selected{{end}}>(GMT +10:00) Eastern Australia, Guam, Vladivostok</option>
<option value="11.0" {{if eq (ToString .Timezone) "11.000000"}}selected{{end}}>(GMT +11:00) Magadan, Solomon Islands, New Caledonia</option>
<option value="12.0" {{if eq (ToString .Timezone) "12.000000"}}selected{{end}}>(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka</option>
</select>
</div>

Expand Down Expand Up @@ -119,6 +119,7 @@ <h3>Settings</h3>
<div class="row align-content-center">
<img class="rounded text-center" width="300" height="300" src="https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl={{ QrAuth }}">
</div>
<a class="btn btn-sm btn-primary" href={{safeURL QrAuth}}>Open in Statup App</a>

</form>

Expand Down
2 changes: 1 addition & 1 deletion source/tmpl/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="col-12">
{{ if .Error }}
<div class="alert alert-danger" role="alert">
{{ .Error }}
{{ .Error }}
</div>
{{ end }}
<form method="POST" id="setup_form" action="/setup">
Expand Down

0 comments on commit c4b1a53

Please sign in to comment.