Skip to content

Commit

Permalink
Merge pull request #12 from vixen-project/add-text-tag-type
Browse files Browse the repository at this point in the history
Add a new "text" tag type.
  • Loading branch information
prabhuramachandran committed Jan 16, 2018
2 parents 8c9a0df + 884d17b commit 0047840
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
5 changes: 4 additions & 1 deletion vixen/html/vixen_ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ <h3> Edit Project</h3>
<label>{{tag.name}}</label>
<select v-model="tag.type" v-bind:id="'tag-type-' + index">
<option>string</option>
<option>text</option>
<option>int</option>
<option>float</option>
<option>bool</option>
Expand Down Expand Up @@ -294,7 +295,9 @@ <h3 style="margin: 5px;"> View Project: {{viewer.name}}</h3>
type="checkbox" v-bind:id="'tag-' + $index">
<input v-if="tag.type == 'string'"
v-model="media.tags[tag.name]" v-bind:id="'tag-' + $index" lazy>
<input v-if="tag.type == 'int' || tag.type == 'float'"
<textarea v-if="tag.type == 'text'"
v-model="media.tags[tag.name]" v-bind:id="'tag-' + $index" lazy></textarea>
<input v-if="tag.type == 'int' || tag.type == 'float'"
v-model="media.tags[tag.name]" number v-bind:id="'tag-' + $index" lazy>
</div>
</div>
Expand Down
8 changes: 5 additions & 3 deletions vixen/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ def _get_csv_headers(fname):

class TagInfo(HasTraits):
name = Str
type = Enum("string", "int", "float", "bool")
type = Enum("string", "text", "int", "float", "bool")
default = Any

def __repr__(self):
return 'TagInfo(%r, %r)' % (self.name, self.type)

def _default_default(self):
map = {"string": "", "int": 0, "float": 0.0, "bool": False}
map = {"string": "", "text": "", "int": 0, "float": 0.0,
"bool": False}
return map[self.type]


Expand Down Expand Up @@ -388,6 +389,7 @@ def import_csv(self, fname):
type_map = {
'bool': lambda x: x.lower() in TRUE,
'string': lambda x: x,
'text': lambda x: x,
'int': int,
'float': float
}
Expand Down Expand Up @@ -587,7 +589,7 @@ def _make_schema(self):
mtime=DATETIME, ctime=DATETIME, size=INT
)
type_to_field = dict(
string=TEXT, int=INT, float=FLOAT, bool=BOOLEAN
string=TEXT, text=TEXT, int=INT, float=FLOAT, bool=BOOLEAN
)
for tag in self.tags:
kw[tag.name] = type_to_field[tag.type]
Expand Down
9 changes: 9 additions & 0 deletions vixen/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys

import unittest
from whoosh.fields import TEXT

from vixen.tests.test_directory import make_data, create_dummy_file
from vixen.project import Project, TagInfo, get_non_existing_filename, INT
Expand Down Expand Up @@ -379,6 +380,14 @@ def test_query_schema_is_updated_when_tags_are_added(self):
items = schema.items()
self.assertIn(('new_tag', INT), items)

# When
p.add_tags([TagInfo(name='tag1', type='text')])

# Then
schema = p._query_parser.schema
items = schema.items()
self.assertIn(('tag1', TEXT()), items)

def test_simple_search_works(self):
# Given
p = Project(name='test', path=self.root)
Expand Down

0 comments on commit 0047840

Please sign in to comment.