Add today time info
This commit is contained in:
parent
a505b23bb1
commit
b40e3827b4
@ -7,6 +7,9 @@
|
||||
<a v-if="started" v-on:click.prevent="finish" href="#">Закончить</a>
|
||||
<a v-else v-on:click.prevent="start" href="#">Начать</a>
|
||||
</section>
|
||||
<section class="today">
|
||||
Сегодня {{ today_time }}
|
||||
</section>
|
||||
<p class="profile-info">Профиль: {{ profileId }}</p>
|
||||
</div>
|
||||
</template>
|
||||
@ -21,12 +24,13 @@ export default {
|
||||
status: '',
|
||||
hours: 0,
|
||||
minutes: 0,
|
||||
today: null,
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.profileId = h.extract_profile_id();
|
||||
this.get_status();
|
||||
setInterval(() => this.get_status(), 30 * 1000);
|
||||
setInterval(() => this.get_status(), 60 * 1000);
|
||||
},
|
||||
computed: {
|
||||
time() {
|
||||
@ -36,14 +40,19 @@ export default {
|
||||
isOvertime() {
|
||||
return this.status === 'overtime';
|
||||
},
|
||||
today_time() {
|
||||
const sign = this.today.status === 'overtime' ? '+' : '';
|
||||
return sign + this.today.hours + ':' + String(this.today.minutes).padStart(2, '0');
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
get_status() {
|
||||
h.get_status(this.profileId).then(data => {
|
||||
this.started = data.started;
|
||||
this.status = data.status;
|
||||
this.hours = data.hours;
|
||||
this.minutes = data.minutes;
|
||||
this.status = data.total.status;
|
||||
this.hours = data.total.hours;
|
||||
this.minutes = data.total.minutes;
|
||||
this.today = data.today;
|
||||
});
|
||||
},
|
||||
start() {
|
||||
@ -76,4 +85,13 @@ export default {
|
||||
.actions {
|
||||
font-size: 240%;
|
||||
}
|
||||
|
||||
.today {
|
||||
margin-top: 1em;
|
||||
font-size: 200%;
|
||||
}
|
||||
|
||||
.profile-info {
|
||||
margin-top: 2em;
|
||||
}
|
||||
</style>
|
||||
|
@ -7,7 +7,7 @@ function extract_profile_id() {
|
||||
const q = haystack.substring(haystack.indexOf('?') + 1, haystack.length);
|
||||
const query = qs.parse(q);
|
||||
const profile = query[PROFILE_QUERY] || '';
|
||||
console.log('PROFILE', query, profile);
|
||||
// console.log('PROFILE', query, profile);
|
||||
return profile;
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ async function get_status(profileId) {
|
||||
method: 'GET',
|
||||
});
|
||||
const data = await response.json();
|
||||
console.log('DATA', data);
|
||||
// console.log('DATA', data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
12
spec/entity_spec.cr
Normal file
12
spec/entity_spec.cr
Normal file
@ -0,0 +1,12 @@
|
||||
require "./spec_helper"
|
||||
|
||||
module Dayoff::Test
|
||||
extend self
|
||||
|
||||
describe "can check same date" do
|
||||
planned_date = PlannedDate.new(t(1, 12), 8)
|
||||
date = t(1, 20)
|
||||
res = planned_date.same_date? date
|
||||
res.should be_true
|
||||
end
|
||||
end
|
@ -94,5 +94,11 @@ module Dayoff::Test
|
||||
prof.finish finish_time
|
||||
end
|
||||
end
|
||||
|
||||
it "can calc diff on concrete date" do
|
||||
prof = create_profile
|
||||
span = prof.date_status d(1)
|
||||
span.total_hours.should eq -2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -6,6 +6,9 @@ base_path = ENV["BASE_PATH"]
|
||||
|
||||
puts "Set storage base path: " + base_path
|
||||
|
||||
STATUS_UPTIME = "uptime"
|
||||
STATUS_OVERTIME = "overtime"
|
||||
|
||||
app = Dayoff::App.new base_path
|
||||
|
||||
add_handler CheckProfileHandler.new(app)
|
||||
@ -14,6 +17,16 @@ def now
|
||||
Time.local(Time::Location.load("Europe/Moscow"))
|
||||
end
|
||||
|
||||
def date_status(profile, date)
|
||||
span = profile.date_status date
|
||||
{
|
||||
date: date.to_s("%Y-%m-%d"),
|
||||
status: span < Time::Span.zero ? STATUS_OVERTIME : STATUS_UPTIME,
|
||||
hours: span.abs.total_hours.to_i32,
|
||||
minutes: span.abs.minutes.to_i32,
|
||||
}
|
||||
end
|
||||
|
||||
post "/api/start" do |env|
|
||||
profile = app.profile Dayoff::ProfileId.new(env.get("profile_id").to_s)
|
||||
profile.start now
|
||||
@ -29,7 +42,15 @@ end
|
||||
get "/api/status" do |env|
|
||||
profile = app.profile Dayoff::ProfileId.new(env.get("profile_id").to_s)
|
||||
rem_span = profile.remaining_time now
|
||||
data = Dayoff::StatusResponse.new(profile.started?, rem_span)
|
||||
data = {
|
||||
started: profile.started?,
|
||||
total: {
|
||||
status: rem_span < Time::Span.zero ? STATUS_OVERTIME : STATUS_UPTIME,
|
||||
hours: rem_span.abs.total_hours.to_i32,
|
||||
minutes: rem_span.abs.minutes.to_i32,
|
||||
},
|
||||
today: date_status(profile, now),
|
||||
}
|
||||
env.response.content_type = "application/json"
|
||||
data.to_json
|
||||
end
|
||||
|
@ -26,6 +26,10 @@ module Dayoff
|
||||
def time_span : Time::Span
|
||||
Time::Span.new(hours: hours, minutes: 0, seconds: 0)
|
||||
end
|
||||
|
||||
def same_date?(d : Time) : Bool
|
||||
@date.date == d.date
|
||||
end
|
||||
end
|
||||
|
||||
class WorkRecord
|
||||
@ -78,24 +82,14 @@ module Dayoff
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def on_date(d : Time) : Time::Span
|
||||
if @start.date == d.date
|
||||
fin = @finish || d
|
||||
fin - start
|
||||
else
|
||||
Time::Span.zero
|
||||
end
|
||||
|
||||
STATUS_UPTIME = "uptime"
|
||||
STATUS_OVERTIME = "overtime"
|
||||
|
||||
class StatusResponse
|
||||
JSON.mapping(
|
||||
started: Bool,
|
||||
status: String,
|
||||
hours: Int32,
|
||||
minutes: Int32,
|
||||
)
|
||||
|
||||
def initialize(@started : Bool, ts : Time::Span)
|
||||
zero = Time::Span.zero
|
||||
@status = ts < zero ? STATUS_OVERTIME : STATUS_UPTIME
|
||||
@hours = ts.abs.total_hours.to_i32
|
||||
@minutes = ts.abs.minutes.to_i32
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -71,6 +71,28 @@ module Dayoff
|
||||
planned - worked
|
||||
end
|
||||
|
||||
def date_status(d : Time) : Time::Span
|
||||
planned = get_planned_hours_on_date d
|
||||
worked = get_work_hours_on_date d
|
||||
planned - worked
|
||||
end
|
||||
|
||||
private def get_planned_hours_on_date(d : Time) : Time::Span
|
||||
@pdates.reduce(Time::Span.zero) do |acc, wd|
|
||||
if wd.same_date? d
|
||||
acc + wd.time_span
|
||||
else
|
||||
acc
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private def get_work_hours_on_date(d : Time) : Time::Span
|
||||
@wrecords.reduce(Time::Span.zero) do |acc, wr|
|
||||
acc + wr.on_date d
|
||||
end
|
||||
end
|
||||
|
||||
private def started_point
|
||||
@wrecords.find { |x| x.started? }
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user