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-if="started" v-on:click.prevent="finish" href="#">Закончить</a>
|
||||||
<a v-else v-on:click.prevent="start" href="#">Начать</a>
|
<a v-else v-on:click.prevent="start" href="#">Начать</a>
|
||||||
</section>
|
</section>
|
||||||
|
<section class="today">
|
||||||
|
Сегодня {{ today_time }}
|
||||||
|
</section>
|
||||||
<p class="profile-info">Профиль: {{ profileId }}</p>
|
<p class="profile-info">Профиль: {{ profileId }}</p>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -21,12 +24,13 @@ export default {
|
|||||||
status: '',
|
status: '',
|
||||||
hours: 0,
|
hours: 0,
|
||||||
minutes: 0,
|
minutes: 0,
|
||||||
|
today: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.profileId = h.extract_profile_id();
|
this.profileId = h.extract_profile_id();
|
||||||
this.get_status();
|
this.get_status();
|
||||||
setInterval(() => this.get_status(), 30 * 1000);
|
setInterval(() => this.get_status(), 60 * 1000);
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
time() {
|
time() {
|
||||||
@ -36,14 +40,19 @@ export default {
|
|||||||
isOvertime() {
|
isOvertime() {
|
||||||
return this.status === 'overtime';
|
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: {
|
methods: {
|
||||||
get_status() {
|
get_status() {
|
||||||
h.get_status(this.profileId).then(data => {
|
h.get_status(this.profileId).then(data => {
|
||||||
this.started = data.started;
|
this.started = data.started;
|
||||||
this.status = data.status;
|
this.status = data.total.status;
|
||||||
this.hours = data.hours;
|
this.hours = data.total.hours;
|
||||||
this.minutes = data.minutes;
|
this.minutes = data.total.minutes;
|
||||||
|
this.today = data.today;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
start() {
|
start() {
|
||||||
@ -76,4 +85,13 @@ export default {
|
|||||||
.actions {
|
.actions {
|
||||||
font-size: 240%;
|
font-size: 240%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.today {
|
||||||
|
margin-top: 1em;
|
||||||
|
font-size: 200%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-info {
|
||||||
|
margin-top: 2em;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -7,7 +7,7 @@ function extract_profile_id() {
|
|||||||
const q = haystack.substring(haystack.indexOf('?') + 1, haystack.length);
|
const q = haystack.substring(haystack.indexOf('?') + 1, haystack.length);
|
||||||
const query = qs.parse(q);
|
const query = qs.parse(q);
|
||||||
const profile = query[PROFILE_QUERY] || '';
|
const profile = query[PROFILE_QUERY] || '';
|
||||||
console.log('PROFILE', query, profile);
|
// console.log('PROFILE', query, profile);
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ async function get_status(profileId) {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
});
|
});
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log('DATA', data);
|
// console.log('DATA', data);
|
||||||
return 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
|
prof.finish finish_time
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
@ -6,6 +6,9 @@ base_path = ENV["BASE_PATH"]
|
|||||||
|
|
||||||
puts "Set storage base path: " + base_path
|
puts "Set storage base path: " + base_path
|
||||||
|
|
||||||
|
STATUS_UPTIME = "uptime"
|
||||||
|
STATUS_OVERTIME = "overtime"
|
||||||
|
|
||||||
app = Dayoff::App.new base_path
|
app = Dayoff::App.new base_path
|
||||||
|
|
||||||
add_handler CheckProfileHandler.new(app)
|
add_handler CheckProfileHandler.new(app)
|
||||||
@ -14,6 +17,16 @@ def now
|
|||||||
Time.local(Time::Location.load("Europe/Moscow"))
|
Time.local(Time::Location.load("Europe/Moscow"))
|
||||||
end
|
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|
|
post "/api/start" do |env|
|
||||||
profile = app.profile Dayoff::ProfileId.new(env.get("profile_id").to_s)
|
profile = app.profile Dayoff::ProfileId.new(env.get("profile_id").to_s)
|
||||||
profile.start now
|
profile.start now
|
||||||
@ -29,7 +42,15 @@ end
|
|||||||
get "/api/status" do |env|
|
get "/api/status" do |env|
|
||||||
profile = app.profile Dayoff::ProfileId.new(env.get("profile_id").to_s)
|
profile = app.profile Dayoff::ProfileId.new(env.get("profile_id").to_s)
|
||||||
rem_span = profile.remaining_time now
|
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"
|
env.response.content_type = "application/json"
|
||||||
data.to_json
|
data.to_json
|
||||||
end
|
end
|
||||||
|
@ -26,6 +26,10 @@ module Dayoff
|
|||||||
def time_span : Time::Span
|
def time_span : Time::Span
|
||||||
Time::Span.new(hours: hours, minutes: 0, seconds: 0)
|
Time::Span.new(hours: hours, minutes: 0, seconds: 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def same_date?(d : Time) : Bool
|
||||||
|
@date.date == d.date
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class WorkRecord
|
class WorkRecord
|
||||||
@ -78,24 +82,14 @@ module Dayoff
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
STATUS_UPTIME = "uptime"
|
def on_date(d : Time) : Time::Span
|
||||||
STATUS_OVERTIME = "overtime"
|
if @start.date == d.date
|
||||||
|
fin = @finish || d
|
||||||
class StatusResponse
|
fin - start
|
||||||
JSON.mapping(
|
else
|
||||||
started: Bool,
|
Time::Span.zero
|
||||||
status: String,
|
end
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -71,6 +71,28 @@ module Dayoff
|
|||||||
planned - worked
|
planned - worked
|
||||||
end
|
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
|
private def started_point
|
||||||
@wrecords.find { |x| x.started? }
|
@wrecords.find { |x| x.started? }
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user