Skip to content

Commit

Permalink
Update pickable usage on time entry form to get it working again
Browse files Browse the repository at this point in the history
  • Loading branch information
lovett committed Jan 6, 2017
1 parent d32dac6 commit f1077c9
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 44 deletions.
12 changes: 11 additions & 1 deletion app/Helpers/TimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static function date(Carbon $value)
return $value->format('M n Y');
}

public static function dateField(Carbon $value)
public static function dateField(Carbon $value = null)
{
if (empty($value)) {
return '';
Expand All @@ -117,6 +117,16 @@ public static function dateField(Carbon $value)
return $value->format('Y-m-d');
}

public static function timeField(Carbon $value = null)
{
if (empty($valu)) {
return '';
}

return $value->format('g:i A');
}


public static function ranges() {
return [
'today' => new DateTime(),
Expand Down
8 changes: 2 additions & 6 deletions app/Http/Controllers/TimeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ public function create(Request $request)
$projectId = null;
}

$model = new Time(
[
'start' => new Carbon('now'),
'project_id' => $projectId,
]
);
$model = new Time();
$model->project_id = $projectId;

$previousModel = $request->user()->time();
if ($projectId !== null) {
Expand Down
19 changes: 19 additions & 0 deletions app/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class Time extends Model
{
use SoftDeletes, Search;

/**
* Default values for newly-created instances.
*
* @var array
*/
protected $attributes = [];

/**
* Fields that can be used for searching.
*
Expand Down Expand Up @@ -65,6 +72,18 @@ class Time extends Model
*/
protected $dates = ['deleted_at' => 'datetime'];

public function __construct()
{
$now = new Carbon();

$this->attributes = [
'start' => $now,
'minutes' => 0,
];
parent::__construct();
}


/**
* Master query for getting a list of records.
*
Expand Down
2 changes: 1 addition & 1 deletion resources/views/partials/formgroup-date.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@endif

<div class="col-sm-10 {{ $label ? '' : 'col-sm-offset-2' }}">
{!! Form::text($name, TimeHelper::dateField($model->$name), ['class' => 'form-control']) !!}
{!! Form::text($name, TimeHelper::dateField($model->$name), ['class' => 'form-control', 'v-model' => 'pickResult']) !!}

@if (isset($autofill))
<autofill-hint target="INPUT[name={{ $name }}]" v-bind:value="suggested{{ ucfirst($name) }}" v-bind:previous="previous{{ ucfirst($name) }}"></autofill-hint>
Expand Down
72 changes: 40 additions & 32 deletions resources/views/partials/formgroup-time.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,54 @@
@endif

<div class="col-sm-10 {{ $label ? '' : 'col-sm-offset-2' }}">
<pickable inline-template format="hh:mm AA" initial="{{ date('h:i A') }}">
{!! Form::text($name . $suffix, isset($model->$name)? $model->$name->format('g:i A') : '', ['class' => 'form-control', 'v-model' => 'pickResult']) !!}
{!! Form::text($fieldName, TimeHelper::timeField($model->$name), ['class' => 'form-control', 'v-model' => 'pickResult']) !!}

<p>
<a href="#" @click.prevent="toggle($event)" v-bind:class="{hidden: !isToggled}">
shortcuts
</a>
</p>
<pickable inline-template format="hh:mm AA" initial-value="{{ date('h:i A') }}" target="INPUT[name={{ $fieldName }}]">
<div>
<p>
<a href="#" @click.prevent="toggle($event)" v-bind:class="{hidden: isOpen}">
shortcuts
</a>
</p>

<div class="shortcuts" v-bind:class="{toggled: isToggled}">
<div class="well">
<p>
<span class="label">Hour:</span>
@foreach ($ranges['hour'] as $value)
<a @click.prevent="pick('hh', '{{ $value->format('g') }}')"
<div class="shortcuts" v-bind:class="{toggled: isOpen}">
<div class="well">
<p>
<span class="label">Hour:</span>
@foreach ($ranges['hour'] as $value)
<a @click.prevent="pick('hh', '{{ $value->format('g') }}')"
href="#"
>{{ $value->format('g') }}</a>
@endforeach
</p>
<p>
<span class="label">Minute:</span>
@foreach ($ranges['minute'] as $value)
<a @click.prevent="pick('mm', '{{ $value->format('i') }}')"
href="#"
>{{ $value->format('i') }}</a>
@endforeach
</p>
<p>
<a @click.prevent="pick('AA', 'AM')"
href="#"
>{{ $value->format('g') }}</a>
@endforeach
</p>
<p>
<span class="label">Minute:</span>
@foreach ($ranges['minute'] as $value)
<a @click.prevent="pick('mm', '{{ $value->format('i') }}')"
>AM</a>
<a @click.prevent="pick('AA', 'PM')"
href="#"
>{{ $value->format('i') }}</a>
@endforeach
</p>
<p>
<a @click.prevent="pick('AA', 'AM')"
href="#"
>AM</a>
<a @click.prevent="pick('AA', 'PM')"
href="#"
>PM</a>
</p>
>PM</a>
</p>

<p class="text-center">
<a class="small" href="#" @click.prevent="toggle($event)">
</a>
</p>

</div>
</div>
</div>
</pickable>


@if ($errors->has($name))
<div class="help-block">{{ $errors->first($name)}}</div>
@endif
Expand Down
7 changes: 4 additions & 3 deletions resources/views/time/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

@include('partials.formgroup-standard', ['name' => 'estimatedDuration', 'label' => 'Estimate'])

@include('partials.formgroup-date', ['name' => 'start', 'suffix' => 'Date', 'label' => 'Date', 'ranges' => TimeHelper::ranges()])
@include('partials.formgroup-date', ['name' => 'start', 'label' => 'Date', 'ranges' => TimeHelper::ranges()])

@include('partials.formgroup-time', ['name' => 'start', 'suffix' => 'Time', 'label' => 'Start', 'ranges' => TimeHelper::ranges()])
@include('partials.formgroup-time', ['name' => 'end', 'suffix' => 'Time', 'label' => 'End', 'ranges' => TimeHelper::ranges()])
@include('partials.formgroup-time', ['name' => 'start', 'fieldName' => 'startTime', 'label' => 'Start', 'ranges' => TimeHelper::ranges()])
@include('partials.formgroup-time', ['name' => 'end', 'fieldName' => 'endTime', 'label' => 'End', 'ranges' => TimeHelper::ranges()])

@include('partials.formgroup-textarea', ['name' => 'summary', 'label' => 'Summary'])

Expand Down Expand Up @@ -58,5 +58,6 @@
@include('partials.vue')
<script src="{{ asset('js/pickable.js') }}"></script>
<script src="{{ asset('js/prefill.js') }}"></script>
@include('partials.vue-init');
@include('partials.select2')
@endsection
4 changes: 3 additions & 1 deletion workspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set -u
PROJECT_ROOT=$(pwd)
PROJECT_NAME=$(basename "$PROJECT_ROOT")

STARTPAGE="${STARTPAGE:-.}"

# Start the server if not already running
tmux start-server 2> /dev/null

Expand All @@ -15,7 +17,7 @@ tmux attach-session -d -t "$PROJECT_NAME" || {

## 0: Editor
tmux new-session -d -s "$PROJECT_NAME" bash
tmux send-keys -t "$PROJECT_NAME" "e ." C-m
tmux send-keys -t "$PROJECT_NAME" "$EDITOR $STARTPAGE" C-m

## 1: Shell
tmux new-window -a -t "$PROJECT_NAME" bash
Expand Down

0 comments on commit f1077c9

Please sign in to comment.