Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
archery
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
archery
Commits
f58723c6
Commit
f58723c6
authored
10 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added filter form
parent
2febdf14
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
routes/match.php
+61
-6
61 additions, 6 deletions
routes/match.php
templates/match/list.latte
+27
-2
27 additions, 2 deletions
templates/match/list.latte
with
88 additions
and
8 deletions
routes/match.php
+
61
−
6
View file @
f58723c6
<?php
use
Nette\Forms\Form
;
use
Instante\Bootstrap3Renderer\BootstrapRenderer
;
function
pack_scores
(
$scores
)
{
$blob
=
''
;
foreach
(
$scores
as
$score
)
...
...
@@ -43,16 +46,68 @@ function render_match_action($action) {
};
}
$app
->
get
(
'/match'
,
function
()
use
(
$app
,
$db
,
$user
)
{
function
filter_form
(
$matches
)
{
global
$db
;
$form
=
new
Form
;
$form
->
setRenderer
(
new
BootstrapRenderer
);
$form
->
setAction
(
'match#results'
);
$form
->
setMethod
(
'get'
);
$match_ids
=
array_unique
(
$matches
->
fetchPairs
(
null
,
'id'
));
$tags
=
$db
->
table
(
'tag'
)
->
select
(
'DISTINCT name AS name'
)
->
where
(
array
(
'match_id'
=>
$match_ids
))
->
fetchPairs
(
'name'
,
'name'
);
asort
(
$tags
);
$distances
=
$matches
->
fetchPairs
(
'distance'
,
'distance'
);
asort
(
$distances
);
$form
->
addSelect
(
'distance'
,
'Distance'
,
$distances
)
->
setPrompt
(
'Select a distance'
);
$form
->
addSelect
(
'tag'
,
'Tag'
,
$tags
)
->
setPrompt
(
'Select a tag'
);
$form
->
addText
(
'name'
,
'Name'
);
$form
->
addSubmit
(
'send'
,
'Filter'
);
return
$form
;
}
$app
->
get
(
'/match'
,
function
(
$filter
=
null
)
use
(
$app
,
$db
,
$user
)
{
$user_id
=
$user
->
getId
();
$matches
=
$db
->
table
(
'match'
)
->
where
(
compact
(
'user_id'
))
->
order
(
'created_at'
,
'desc'
);
$app
->
render
(
'match/list'
,
compact
(
'matches'
));
$matches
=
$db
->
table
(
'match'
)
->
where
(
compact
(
'user_id'
))
->
order
(
'created_at DESC'
);
$filter_form
=
filter_form
(
$matches
);
if
(
$filter_form
->
isSubmitted
())
{
$values
=
$filter_form
->
getValues
();
if
(
$values
->
tag
)
{
$ids
=
$db
->
table
(
'tag'
)
->
select
(
'match_id'
)
->
where
(
'name'
,
$values
->
tag
);
$matches
->
where
(
'id'
,
$ids
);
}
if
(
$values
->
distance
)
$matches
->
where
(
'distance'
,
$values
->
distance
);
if
(
$values
->
name
)
$matches
->
where
(
'name LIKE ?'
,
"%
$values->name
%"
);
//foreach ($filter_form->getValues() as $prop => $value) {
//$matches = $matches->where($filter_form->getValues();
}
$app
->
render
(
'match/list'
,
compact
(
'matches'
,
'filter_form'
));
});
$app
->
get
(
'/match/:id'
,
render_match_action
(
'view'
));
$app
->
get
(
'/match/:id/edit'
,
render_match_action
(
'edit'
));
$app
->
get
(
'/match/:id/delete'
,
render_match_action
(
'delete'
));
$app
->
delete
(
'/match/:id'
,
function
(
$id
)
use
(
$app
,
$db
)
{
$db
->
table
(
'user'
)
->
delete
();
//find_match($id)->delete();
$app
->
delete
(
'/match/:id'
,
function
(
$id
)
{
find_match
(
$id
)
->
delete
();
});
$app
->
put
(
'/match/:id'
,
function
(
$id
)
{
// TODO
});
This diff is collapsed.
Click to expand it.
templates/match/list.latte
+
27
−
2
View file @
f58723c6
{extends '../layout.latte'}
{block content}
<table class="table table-hover matches">
<h3 class="page-header">
<a data-toggle="collapse" href="#filter">
Filter matches <span class="caret"></span>
</a>
</h3>
<div id="filter" class="collapse {$filter_form->isSubmitted() ? in}">
{form $filter_form}
{form errors}
{form controls}
<div class="form-group">
<div class="form-actions col-sm-offset-2 col-sm-10">
<button type="submit" name="send" class="btn btn-primary">Filter</button>
<a href="match" class="btn btn-default">Clear filters</a>
</div>
</div>
{/form}
<h3>Results</h3>
</div>
<table id="results" class="table table-hover matches">
<thead>
<tr>
<th>Name</th>
...
...
@@ -25,7 +44,13 @@
<td>{match_score($match)} (~{match_avg_score($match)|number:1})</td>
</tr>
<tr n:if="!$matches->count()">
<td colspan="5">You have not saved any matches yet.</td>
<td colspan="5">
{if $filter_form->isSubmitted()}
No search results.
{else}
You have not saved any matches yet.
{/if}
</td>
</tr>
</tbody>
</table>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment