Let team members search team snipts.
parent
bac36dc309
commit
1b929e79c8
1
Makefile
1
Makefile
|
@ -34,7 +34,6 @@ assets:
|
||||||
> media/css/snipt.css
|
> media/css/snipt.css
|
||||||
@cat media/js/src/account.js > media/js/src/account.min.js
|
@cat media/js/src/account.js > media/js/src/account.min.js
|
||||||
@cat media/js/src/snipts.js > media/js/src/snipts.min.js
|
@cat media/js/src/snipts.js > media/js/src/snipts.min.js
|
||||||
@cat media/js/src/search.js > media/js/src/search.min.js
|
|
||||||
@cat media/js/src/jobs.js > media/js/src/jobs.min.js
|
@cat media/js/src/jobs.js > media/js/src/jobs.min.js
|
||||||
@cat media/js/src/application.js > media/js/src/application.min.js
|
@cat media/js/src/application.js > media/js/src/application.min.js
|
||||||
@cat media/js/src/team.js > media/js/src/team.min.js
|
@cat media/js/src/team.js > media/js/src/team.min.js
|
||||||
|
|
|
@ -32,7 +32,6 @@ cat media/css/bootstrap.min.css \
|
||||||
|
|
||||||
cat media/js/src/account.js|jsmin > media/js/src/account.min.js
|
cat media/js/src/account.js|jsmin > media/js/src/account.min.js
|
||||||
cat media/js/src/snipts.js|jsmin > media/js/src/snipts.min.js
|
cat media/js/src/snipts.js|jsmin > media/js/src/snipts.min.js
|
||||||
cat media/js/src/search.js|jsmin > media/js/src/search.min.js
|
|
||||||
cat media/js/src/jobs.js|jsmin > media/js/src/jobs.min.js
|
cat media/js/src/jobs.js|jsmin > media/js/src/jobs.min.js
|
||||||
cat media/js/src/application.js|jsmin > media/js/src/application.min.js
|
cat media/js/src/application.js|jsmin > media/js/src/application.min.js
|
||||||
cat media/js/src/team.js|jsmin > media/js/src/team.min.js
|
cat media/js/src/team.js|jsmin > media/js/src/team.min.js
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -3132,3 +3132,29 @@ div.payment-form {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
width: 86%;
|
width: 86%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.with-teams-search {
|
||||||
|
display: inline-block;
|
||||||
|
width: 87%;
|
||||||
|
|
||||||
|
input.search-query {
|
||||||
|
width: 69% !important;
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
display: inline-block;
|
||||||
|
width: 25%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
div.team-search {
|
||||||
|
form {
|
||||||
|
margin: 0;
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
input {
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 0;
|
||||||
|
padding: 15px 10px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
(function() {
|
|
||||||
|
|
||||||
if (typeof angular !== 'undefined') {
|
|
||||||
|
|
||||||
var root = this;
|
|
||||||
var $ = root.jQuery;
|
|
||||||
var controllers = {};
|
|
||||||
var app = root.app;
|
|
||||||
|
|
||||||
// Services.
|
|
||||||
app.factory('SearchService', function() {
|
|
||||||
return {
|
|
||||||
mineOnly: false,
|
|
||||||
query: ''
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// Controllers.
|
|
||||||
controllers.HeaderSearchController = function($scope, SearchService) {
|
|
||||||
|
|
||||||
$scope.search = SearchService;
|
|
||||||
|
|
||||||
};
|
|
||||||
controllers.SearchController = function($scope, SearchService) {
|
|
||||||
|
|
||||||
$scope.search = SearchService;
|
|
||||||
|
|
||||||
$scope.$watch('search.query', function(query) {
|
|
||||||
if (query.indexOf('--mine') !== -1) {
|
|
||||||
$scope.search.mineOnly = true;
|
|
||||||
} else {
|
|
||||||
$scope.search.mineOnly = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$scope.toggleMineOnly = function() {
|
|
||||||
if ($scope.search.mineOnly) {
|
|
||||||
|
|
||||||
// Make sure '--mine' exists somewhere in the query.
|
|
||||||
if ($scope.search.query.indexOf('--mine') === -1) {
|
|
||||||
$scope.search.query = $scope.search.query.trim() + ' --mine';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$scope.search.query = $scope.search.query.replace('--mine', '').trim();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// Assign the controllers.
|
|
||||||
app.controller(controllers);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}).call(this);
|
|
|
@ -14,6 +14,7 @@ from haystack.query import EmptySearchQuerySet, SearchQuerySet
|
||||||
from pygments.lexers import get_lexer_by_name
|
from pygments.lexers import get_lexer_by_name
|
||||||
from snipts.models import Favorite, Snipt
|
from snipts.models import Favorite, Snipt
|
||||||
from taggit.models import Tag
|
from taggit.models import Tag
|
||||||
|
from teams.models import Team
|
||||||
|
|
||||||
RESULTS_PER_PAGE = getattr(settings, 'HAYSTACK_SEARCH_RESULTS_PER_PAGE', 20)
|
RESULTS_PER_PAGE = getattr(settings, 'HAYSTACK_SEARCH_RESULTS_PER_PAGE', 20)
|
||||||
|
|
||||||
|
@ -286,17 +287,33 @@ def search(request, template='search/search.html', load_all=True,
|
||||||
query = ''
|
query = ''
|
||||||
results = EmptySearchQuerySet()
|
results = EmptySearchQuerySet()
|
||||||
|
|
||||||
# We have a query.
|
|
||||||
if request.GET.get('q'):
|
if request.GET.get('q'):
|
||||||
|
|
||||||
if request.user.is_authenticated() and '--mine' in \
|
searchqueryset = SearchQuerySet() \
|
||||||
request.GET.get('q'):
|
.filter(Q(public=True) | Q(author=request.user)) \
|
||||||
|
.order_by('-pub_date')
|
||||||
|
|
||||||
|
if request.user.is_authenticated() and \
|
||||||
|
'mine-only' in request.GET:
|
||||||
searchqueryset = SearchQuerySet().filter(author=request.user) \
|
searchqueryset = SearchQuerySet().filter(author=request.user) \
|
||||||
.order_by('-pub_date')
|
.order_by('-pub_date')
|
||||||
else:
|
|
||||||
searchqueryset = SearchQuerySet() \
|
elif request.user.is_authenticated() and \
|
||||||
.filter(Q(public=True) | Q(author=request.user)) \
|
('author' in request.GET and
|
||||||
.order_by('-pub_date')
|
request.GET.get('author')):
|
||||||
|
|
||||||
|
author = request.GET.get('author')
|
||||||
|
|
||||||
|
if author == request.user.username:
|
||||||
|
searchqueryset = SearchQuerySet().filter(author=request.user) \
|
||||||
|
.order_by('-pub_date')
|
||||||
|
|
||||||
|
else:
|
||||||
|
team = get_object_or_None(Team, slug=author)
|
||||||
|
|
||||||
|
if team and team.user_is_member(request.user):
|
||||||
|
searchqueryset = SearchQuerySet().filter(author=team) \
|
||||||
|
.order_by('-pub_date')
|
||||||
|
|
||||||
form = ModelSearchForm(request.GET,
|
form = ModelSearchForm(request.GET,
|
||||||
searchqueryset=searchqueryset,
|
searchqueryset=searchqueryset,
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
from django import template
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def user_is_member(team, user):
|
||||||
|
return team.user_is_member(user)
|
|
@ -75,7 +75,7 @@
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<div class="shadey"></div>
|
<div class="shadey"></div>
|
||||||
<h1 class="main-logo"><a href="{% if request.user.is_authenticated %}/{{ request.user.username }}/{% else %}/{% endif %}">snip<span>t</span></a></h1>
|
<h1 class="main-logo"><a href="{% if request.user.is_authenticated %}/{{ request.user.username }}/{% else %}/{% endif %}">snip<span>t</span></a></h1>
|
||||||
<form class="search" action="/search/" method="get" ng-controller="HeaderSearchController">
|
<form class="search" action="/search/" method="get">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<div class="fields">
|
<div class="fields">
|
||||||
<input ng-model="search.query" type="text" class="search-query" name="q"
|
<input ng-model="search.query" type="text" class="search-query" name="q"
|
||||||
|
@ -433,7 +433,6 @@
|
||||||
<script type="text/javascript" src="{{ STATIC_URL }}js/src/modules/snipt.js"></script>
|
<script type="text/javascript" src="{{ STATIC_URL }}js/src/modules/snipt.js"></script>
|
||||||
<script type="text/javascript" src="{{ STATIC_URL }}js/src/account.js"></script>
|
<script type="text/javascript" src="{{ STATIC_URL }}js/src/account.js"></script>
|
||||||
<script type="text/javascript" src="{{ STATIC_URL }}js/src/snipts.js"></script>
|
<script type="text/javascript" src="{{ STATIC_URL }}js/src/snipts.js"></script>
|
||||||
<script type="text/javascript" src="{{ STATIC_URL }}js/src/search.js"></script>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<script type="text/javascript" src="{{ STATIC_URL }}js/snipt-all.min.js?74"></script>
|
<script type="text/javascript" src="{{ STATIC_URL }}js/snipt-all.min.js?74"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% load snipt_tags %}
|
{% load snipt_tags team_tags %}
|
||||||
|
|
||||||
{% if user.profile.is_a_team %}
|
{% if user.profile.is_a_team %}
|
||||||
<div class="profile group">
|
<div class="profile group">
|
||||||
|
@ -27,6 +27,16 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% if user.team|user_is_member:request.user %}
|
||||||
|
<div class="profile team-settings group">
|
||||||
|
<div class="team-search">
|
||||||
|
<form action="/search/" method="get">
|
||||||
|
<input type="text" class="text" value="" name="q" placeholder="Search team snipts...">
|
||||||
|
<input type="hidden" class="text" value="{{ user.username }}" name="author">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% if user.team.owner == request.user %}
|
{% if user.team.owner == request.user %}
|
||||||
<div class="profile team-settings group">
|
<div class="profile team-settings group">
|
||||||
<div class="meta">
|
<div class="meta">
|
||||||
|
|
|
@ -22,15 +22,47 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<section class="snipts" id="snipts"></section>
|
<section class="snipts" id="snipts"></section>
|
||||||
<div class="static-box {% if page.object_list|length > 0 %}has-snipts{% endif %}">
|
<div class="static-box {% if page.object_list|length > 0 %}has-snipts{% endif %}">
|
||||||
<form method="get" class="form-search" action="." ng-controller="SearchController">
|
<form method="get" class="form-search" action=".">
|
||||||
<input ng-model="search.query" type="text" class="search-query" name="q"
|
{% if not request.user.profile.has_teams %}
|
||||||
ng-init="search.query='{{ query|escapejs }}'"
|
<input type="text" class="search-query" name="q"
|
||||||
placeholder="Search snipts" id="id_q"
|
placeholder="Search snipts" id="id_q"
|
||||||
value="{{ query }}" />
|
value="{{ query }}" />
|
||||||
<label class="checkbox inline mine-only" ng-click="toggleMineOnly()">
|
{% if request.user.is_authenticated %}
|
||||||
<input {% if '--mine' in query %}checked="checked"{% endif %} ng-model="search.mineOnly" type="checkbox" id="inlineCheckbox1" value="option1"> Mine only
|
<label class="checkbox inline mine-only">
|
||||||
</label>
|
<input {% if 'mine-only' in request.GET %}checked{% endif %} type="checkbox" name="mine-only"> Mine only
|
||||||
<button type="submit" class="btn">Search</button>
|
</label>
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
<div class="with-teams-search">
|
||||||
|
<input type="text" class="search-query" name="q"
|
||||||
|
placeholder="Search snipts" id="id_q"
|
||||||
|
value="{{ query }}"
|
||||||
|
/>
|
||||||
|
<select name="author">
|
||||||
|
<option
|
||||||
|
{% if not request.GET.author or request.GET.author == '' %}selected{% endif %}
|
||||||
|
value=""
|
||||||
|
>
|
||||||
|
Mine and all public
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
{% if request.GET.author == request.user.username %}selected{% endif %}
|
||||||
|
value="{{ request.user.username }}"
|
||||||
|
>
|
||||||
|
Mine only
|
||||||
|
</option>
|
||||||
|
{% for team in request.user.profile.teams %}
|
||||||
|
<option
|
||||||
|
{% if request.GET.author == team.slug %}selected{% endif %}
|
||||||
|
value="{{ team.slug }}"
|
||||||
|
>
|
||||||
|
{{ team.name }}
|
||||||
|
</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
<button type="submit" class="btn">Search</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{% if query %}
|
{% if query %}
|
||||||
|
|
Loading…
Reference in New Issue