Skip to content

Commit

Permalink
fixing up tags, and labels, and having From: statement automatically …
Browse files Browse the repository at this point in the history
…parsed as tag
  • Loading branch information
vsoch committed Aug 21, 2017
1 parent 1c7838d commit 79c1457
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 148 deletions.
8 changes: 8 additions & 0 deletions shub/apps/api/actions/create.py
Expand Up @@ -72,6 +72,14 @@ def add_metadata(container,metadata,field):
except:
pass

# If exists, add From line as tag
try:
container_from = metadata['labels']['SREGISTRY_FROM']
container.tags.add(container_from)
container.save()
except:
pass

# Add labels
if metadata['labels'] not in [None,'']:
container = update_container_labels(container,metadata['labels'])
Expand Down
2 changes: 1 addition & 1 deletion shub/apps/base/templates/base/navigation.html
Expand Up @@ -14,7 +14,7 @@
<ul class="dropdown-menu">
<li><a href="{% url 'collections' %}">Collections</a></li>
<li><a href="{% url 'all_labels' %}">Labels</a></li>
<li><a href="{% url 'all_tags' %}">Tags</a></li>
<li><a href="{% url 'all_tags' %}">Topic Tags</a></li>
</ul>
</li>

Expand Down
18 changes: 1 addition & 17 deletions shub/apps/base/templates/search/result.html
Expand Up @@ -4,7 +4,7 @@
{% if results|length %}
<table>
<tr class="even">
<td colspan="5" class="right">
<td colspan="4" class="right">
<strong>Found {{ results|length }} collections</strong>
</td>
</tr>
Expand All @@ -18,22 +18,6 @@
</td>
<td>
<a href="{% url 'collection_details' collection.id %}">
{% if collection.tags.count > 0 %}
{% for tag in collection.tags.all %}
<a href="{% url 'view_tag' tag.id %}">
<button style="margin-top:15px" class="btn btn-default btn-xs">
{{ tag.name }}</button></a>
{% endfor %}
{% endif %}
</td>
<td>
{% for container in collection.containers.all %}
{% for label in container.labels %}
<a href="{% url 'view_label' label.id %}">
<button class="btn btn-default btn-xs">
{{ label.key }}</button></a>
{% endfor %}
{% endfor %}
</td>
<td class="right">
<span class="hint">
Expand Down
3 changes: 1 addition & 2 deletions shub/apps/main/models.py
Expand Up @@ -114,7 +114,6 @@ class Collection(models.Model):
modify_date = models.DateTimeField('date modified', auto_now=True)
secret = models.CharField(max_length=200, null=False, verbose_name="Collection secret for webhook")
metadata = JSONField(default={}) # open field for metadata about a collection
tags = TaggableManager()

# Users
owner = models.ForeignKey('users.User', blank=True, default=None, null=True)
Expand Down Expand Up @@ -211,6 +210,7 @@ class Container(models.Model):
tag = models.CharField(max_length=250,null=False,blank=False,default="latest")
secret = models.CharField(max_length=250,null=True,blank=True)
version = models.CharField(max_length=250,null=True,blank=True)
tags = TaggableManager()
frozen = models.BooleanField(choices=FROZEN_CHOICES,
default=False,
verbose_name="is the container frozen, meaning builds will not be replaced?")
Expand Down Expand Up @@ -262,7 +262,6 @@ def __unicode__(self):
return self.get_uri()



class Meta:
ordering = ['name']
app_label = 'main'
Expand Down
4 changes: 2 additions & 2 deletions shub/apps/main/query.py
Expand Up @@ -40,7 +40,7 @@ def collection_query(q):
return Collection.objects.filter(
Q(name__contains=q) |
Q(containers__name__contains=q) |
Q(tags__name__contains=q) |
Q(containers__tags__name__contains=q) |
Q(containers__tag__contains=q)).distinct()


Expand Down Expand Up @@ -69,7 +69,7 @@ def container_query(q, across_collections=1):
return Collection.objects.filter(
Q(name__contains=q['image']) |
Q(collection__name__contains=q['collection']) |
Q(tag__contains=q['tag'])).distinct()
Q(containers_tags__contains=q['tag'])).distinct()

# Query a particular collection for image name
return Collection.objects.filter(
Expand Down
97 changes: 12 additions & 85 deletions shub/apps/main/templates/collections/view_collection.html
@@ -1,5 +1,4 @@
{% extends "base/base.html" %}
{% load crispy_forms_tags %}
{% load staticfiles %}

{% block css %}
Expand All @@ -13,13 +12,7 @@
padding-left: 7px !important;
min-width:20px !important;
}
#collection_tags {
float:right;
background:white;
border-radius:10px;
border:none;
margin-bottom:50px
}

#star {
padding-left:25px;
float:right;
Expand All @@ -28,8 +21,6 @@
cursor:pointer;
}
</style>
<link rel="stylesheet" type="text/css" href="{% static "css/tagit.theme.css" %}">
<link href="{% static "css/jquery.tagit.css"%}" rel="stylesheet" type="text/css">
{% endblock %}

{% block content %}
Expand All @@ -39,34 +30,19 @@
<div class="row" style="margin-top:30px">

<!-- Container collection meta -->
<div class="col-md-4">
<div class="col-md-10">
<h3 class="title">{{ collection.name }} <span class="small">collection</span></h3>
</div>
<div class="col-md-6">

<div class="card">
<div class="header">

{% if collection.tags.count > 0 %}
<ul id="collection_tags">
{% for tag in collection.tags.all %}
<li name="{{ tag.name }}" id="{{ tag.id }}">{{ tag.name }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
</div>
<div class="col-md-2">

<!--Star Rating-->
{% if user.is_authenticated %}
{% if star %}
<i id="star" class="fa fa-star"></i>
{% else %}
<i id="star" class="fa fa-star-o"></i>
{% endif %}
{% endif %}
<!--Star Rating-->
{% if user.is_authenticated %}
{% if star %}
<i id="star" class="fa fa-star"></i>
{% else %}
<i id="star" class="fa fa-star-o"></i>
{% endif %}
{% endif %}

</div>
</div>
Expand Down Expand Up @@ -245,23 +221,8 @@ <h3 class="title">{{ collection.name }} <span class="small">collection</span></h
$('.table-header').css('width',$("table").css('width'))
$('.paginate_button').remove()

{% if collection.tags.count > 0 %}
$("#collection_tags").tagit({
removeConfirmation:true,
{% if edit_permission %}
afterTagRemoved: function(event, ui) {
removeTag(ui.tagLabel);
},
afterTagAdded: function(event, ui) {
addTag(ui.tagLabel);
}
{% else %}
readOnly:true
{% endif %}
});
{% endif %}

{% if user.is_authenticated %}
{% if user.is_authenticated %}
console.log('Hello {{ user.username }}!')

$("#star").click(function(){
Expand Down Expand Up @@ -290,42 +251,8 @@ <h3 class="title">{{ collection.name }} <span class="small">collection</span></h
}
});
}
{% endif %}


{% if edit_permission %}
function addTag(tag) {

$.ajax({
url : "{% url 'add_tag' collection.id %}",
type : "POST",
data: { tag : tag },

success : function(json) {
console.log("Woohoo, tagalicious!");
},
error : function(xhr,errmsg,err) {
console.log(xhr.status + ": " + xhr.responseText); // provide a bit more info about the error to the console
}
});
}

function removeTag(tag) {

$.ajax({
url : "{% url 'remove_tag' collection.id %}",
type : "POST",
data: { tag : tag },
{% endif %}

success : function(json) {
console.log(json);
},
error : function(xhr,errmsg,err) {
console.log(xhr.status + ": " + xhr.responseText);
}
});
}
{% endif %}

// Check with the user before deleting a container
$(".delete_container").click(function(){
Expand Down
75 changes: 74 additions & 1 deletion shub/apps/main/templates/containers/container_details.html
Expand Up @@ -14,6 +14,15 @@
margin-bottom:2px;
}

#container_tags {
float:right;
background:white;
border-radius:10px;
border:none;
margin-bottom:50px
}


#id_spec {
position: absolute;
height:800px;
Expand All @@ -23,6 +32,8 @@
left: 0;
}
</style>
<link rel="stylesheet" type="text/css" href="{% static "css/tagit.theme.css" %}">
<link href="{% static "css/jquery.tagit.css"%}" rel="stylesheet" type="text/css">
{% endblock %}

{% block content %}
Expand All @@ -47,7 +58,6 @@
</div>

<div class="row">

<div class="col-md-12">
<div class="card" style="padding:20px">
<div class="header">
Expand All @@ -58,7 +68,16 @@ <h3>
<span class="icon-controls" style="position:relative;top:-70px">
</span>
</h3>

{% if container.tags.count > 0 %}
<ul id="container_tags">
{% for tag in container.tags.all %}
<li name="{{ tag.name }}" id="{{ tag.id }}">{{ tag.name }}</li>
{% endfor %}
</ul>
{% endif %}
</div>

<div class="content" style="padding-bottom:20px">

{% if edit_permission %}
Expand Down Expand Up @@ -249,6 +268,8 @@ <h3>n={{ label.containers.count }}</h3>
<script src="{% static "js/ace.js"%}" type="text/javascript" charset="utf-8"></script>
<script src="{% static "js/clipboard.min.js"%}"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/highlight.min.js"></script>
<script src="{% static "js/jquery-ui.min.js"%}" type="text/javascript" charset="utf-8"></script>
<script src="{% static "js/tag-it.min.js"%}" type="text/javascript" charset="utf-8"></script>
<script>

function make_editor(divname) {
Expand Down Expand Up @@ -292,6 +313,58 @@ <h3>n={{ label.containers.count }}</h3>
make_editor("environment")
{% endif %}


// Add topic tags to container
$("#container_tags").tagit({
removeConfirmation:true,
{% if edit_permission %}
afterTagRemoved: function(event, ui) {
removeTag(ui.tagLabel);
},
afterTagAdded: function(event, ui) {
addTag(ui.tagLabel);
}
{% else %}
readOnly:true
{% endif %}
});


{% if edit_permission %}
function addTag(tag) {

$.ajax({
url : "{% url 'add_tag' container.id %}",
type : "POST",
data: { tag : tag },

success : function(json) {
console.log("Woohoo, tagalicious!");
},
error : function(xhr,errmsg,err) {
console.log(xhr.status + ": " + xhr.responseText); // provide a bit more info about the error to the console
}
});
}

function removeTag(tag) {

$.ajax({
url : "{% url 'remove_tag' container.id %}",
type : "POST",
data: { tag : tag },

success : function(json) {
console.log(json);
},
error : function(xhr,errmsg,err) {
console.log(xhr.status + ": " + xhr.responseText);
}
});
}
{% endif %}


// Load highlighter for highlight js (log)
hljs.initHighlightingOnLoad();

Expand Down
6 changes: 3 additions & 3 deletions shub/apps/main/templates/tags/all_tags.html
Expand Up @@ -46,7 +46,7 @@
<h3 class="title">
<img src="{% static 'img/robot_vision.png' %}"
width="160px" style="position:relative;top:-5px;border-radius:35px; padding-right:10px;margin-right:10px"/>
Tags!</h3>
Topic Tags</h3>
</div>
</div>
</div>
Expand All @@ -56,8 +56,8 @@ <h3 class="title">
<div class="row">
<div class="col-md-12">
<div class="mdl-tooltip">
Tags are derived automatically from Github topics, and collection owners can adjust as needed.
<span style='float:right'><a href="{% url 'search' %}"><i class="fa fa-search"></i></a></span>
Topic tags are added by users to individual containers, along with the "From:" statement of the build recipe.
<!--<span style='float:right'><a href="{% url 'search' %}"><i class="fa fa-search"></i></a></span>-->
</div>
</div>
</div>
Expand Down

0 comments on commit 79c1457

Please sign in to comment.