(79 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | {{Team:William_and_Mary/CSS_RESET}} | + | {{Team:William_and_Mary/CSS_RESET}} {{Team:William_and_Mary/CSS_FIX}} {{Team:William_and_Mary/SOURCE}} {{Team:William_and_Mary/HEADER2}} |
− | {{Team:William_and_Mary/CSS_FIX}} | + | |
− | {{Team:William_and_Mary/SOURCE}} | + | |
− | {{Team:William_and_Mary/HEADER2}} | + | |
<html lang="en"> | <html lang="en"> | ||
<head> | <head> | ||
− | + | <meta charset="UTF-8"> | |
− | + | <title>Outreach Database: select tags for search</title> | |
− | + | <style> | |
− | + | ul.tag-type { | |
− | + | list-style: none; | |
− | + | column-width: 300px; | |
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | div.search-result { | |
− | + | margin-top: 30px; | |
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | .school-info { | |
− | + | color: #006621; | |
− | + | } | |
− | + | .tag-label { | |
+ | margin-left: 15px; | ||
+ | vertical-align: top; | ||
+ | width: 260px; | ||
+ | font-size: 16px; | ||
+ | } | ||
− | + | .tag { | |
− | + | display: inline-block; | |
− | + | } | |
− | + | </style> | |
− | + | <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.10/handlebars.min.js"></script> | |
− | + | <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.2.min.js"></script> | |
− | + | <script src='https://cdnjs.cloudflare.com/ajax/libs/tabletop.js/1.5.1/tabletop.min.js'></script> | |
− | + | <script src="http://cdn.jsdelivr.net/alasql/0.3/alasql.min.js"></script> | |
− | + | <script src='https://2017.igem.org/Team:William_and_Mary/outreach_db_js?action=raw&ctype=text/javascript' type='text/javascript'></script> | |
− | + | <script src='https://cdnjs.cloudflare.com/ajax/libs/fuse.js/3.0.4/fuse.min.js'></script> | |
− | + | <!--script src='outreach_db.js'></script--> | |
+ | |||
+ | |||
+ | |||
+ | |||
+ | <script id="checkbox-area-template" type="text/x-handlebars-template"> | ||
+ | {{#each this}} | ||
+ | <fieldset id='{{@key}}' value='{{@key}}'> | ||
+ | <legend style='cursor: pointer'>{{@key}}</legend> | ||
+ | <ul class='tag-type' style='display:none'> | ||
+ | {{#each this}} | ||
+ | <li class='tag'> | ||
+ | <input type='checkbox' name='{{@../key}}' value='{{this}}' class='tag-checkbox' /><label class='tag-label'>{{this}}</label> | ||
+ | </li> | ||
+ | <br> {{/each}} | ||
+ | </ul> | ||
+ | </fieldset> | ||
+ | {{/each}} | ||
+ | </script> | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | <script id="querystring-template" type="text/x-handlebars-template"> | ||
+ | {{#each this}} {{#if @first}} WHERE {{/if}} ( {{#each this}} [{{@../key}}] LIKE ("%{{this}}%") {{#unless @last}} OR {{/unless}} {{/each}} ) {{#unless @last}}AND{{/unless}} {{/each}} | ||
+ | </script> | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | <!--Search Results------> | ||
+ | |||
+ | |||
+ | <script id="search-results-template" type="text/x-handlebars-template"> | ||
+ | |||
+ | {{#each this}} | ||
+ | <div class='search-result' style="background-color:#DBDBDB; text-align:left; vertical-align: middle; padding:20px 47px;"> | ||
+ | <div class='project-title' style='font-size: 25px; margin-right: 250px;'><b>{{[Outreach Project]}}</b></div> | ||
+ | <div style='font-size: 17px; padding-top: 0px; padding-bottom: 6px;margin-top:-30px;'><span class="pull-right"><a class='school-info' href='{{[Wiki hyperlink]}}'>{{[School]}} {{[Year]}} {{[School Level]}}</a></span></div> | ||
+ | |||
+ | <div style='font-size: 20px; padding-top: 26px; padding-bottom: px;'><span class="pull-right"><span class='outreach-category'>{{[Outreach Category]}}</span></span> | ||
+ | </div> | ||
+ | <div style='font-size: 17px; padding-bottom: 15px;padding-left: 10px;margin-top: 5px; margin-right: 350px;text-indent: px;'> | ||
+ | {{[Description]}} | ||
+ | </div> | ||
+ | <dl> | ||
+ | {{#if [Award]}} | ||
+ | <dt style="font-size:20px;"> | ||
Award | Award | ||
− | </dt> | + | </dt>{{/if}} |
− | + | <dd> | |
− | + | {{#if [Award]}}<div style='font-size: 16px;'> | |
− | + | {{[Award]}}</div>{{/if}} | |
− | + | </dd> | |
+ | <dt style="font-size:20px;"> | ||
Project Tag | Project Tag | ||
</dt> | </dt> | ||
− | + | <dd> | |
− | + | <div style='font-size: 16px;'> | |
− | + | {{[Project Tag]}}</div> | |
− | + | </dd> | |
− | + | </dl> | |
− | + | <a class='details-link' href='#' outreach-id='{{id}}'>Details</a> | |
− | + | </div> | |
+ | {{/each}} | ||
− | + | </script> | |
− | + | <!---end of search results---> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | <script id=mv type=text/x-handlebars-template> | ||
+ | <div class='details-page'> | ||
+ | <h1 class='project-title'>{{[Outreach Project]}}</h1> | ||
+ | <a class='school-info' href='{{[Wiki hyperlink]}}'>{{[School]}}-{{[Year]}}-{{[School Level]}}</a> | ||
+ | <br/> | ||
+ | <span class='outreach-category'>{{[Outreach Category]}}</span> | ||
+ | <p> | ||
+ | {{{[Product Description]}}} | ||
+ | </p> | ||
− | + | {{#each this}} | |
+ | <h2>{{@key}}:</h2> | ||
− | + | <div> | |
− | + | {{{this}}} | |
+ | </div> | ||
+ | {{/each}} | ||
+ | </div> | ||
+ | </script> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | ||
− | + | <script type='text/javascript'> | |
− | + | $(document).ready(function() { | |
− | + | var OUTREACH_URL = 'https://docs.google.com/spreadsheets/d/1lkZSXS3HXTS_ZyPZytyIW0Keer_aKy8rr1_pxV2-fSs/pubhtml?gid=1097044156&single=true' | |
− | + | outreach_db.init().then( // scrape all tags from data | |
− | + | outreach_db.list_tags | |
+ | ).then( // initialize checkbox area using tag data | ||
+ | init_checkbox_area | ||
+ | ).then( // now that we have the checkboxes, we can hook them up with the search function | ||
+ | function() { | ||
+ | $('#checkbox-area input').change(search); | ||
+ | $("fieldset legend").click(function() { | ||
+ | console.log('legend clicked', this) | ||
+ | $(this).parent().find(".tag-type").toggle(); | ||
+ | }); | ||
+ | outreach_arr = alasql('select * from outreach') | ||
+ | var options = { | ||
+ | shouldSort: true, | ||
+ | threshold: 0.6, | ||
+ | location: 0, | ||
+ | distance: 100, | ||
+ | maxPatternLength: 32, | ||
+ | minMatchCharLength: 1, | ||
+ | keys: Object.keys(outreach_arr[0]) | ||
+ | }; | ||
+ | fuse = new Fuse(outreach_arr, options); // "list" is the item array | ||
+ | } | ||
+ | ); | ||
+ | }); | ||
+ | |||
+ | function read_checkbox_area() { | ||
+ | var checked_tags = {} | ||
+ | // returns array of form {tag_type: [tag, tag, tag], tag_type2: [tag, tag, tag]} | ||
+ | $('#checkbox-area fieldset').each(function(idx, elm) { | ||
+ | checked_tags[$(elm).attr('value')] = $(elm).find('input:checked').map(function(idx1, elm1) { | ||
+ | return $(elm1).attr('value') | ||
+ | }).get() | ||
+ | }) | ||
+ | console.log(checked_tags) | ||
+ | return checked_tags; | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | function search() { | ||
+ | |||
+ | // From light comes darkness, and from darkness, light. | ||
+ | // i.e. Don't filter types of which no tags has been selected | ||
+ | |||
+ | var ordburl = 'https://docs.google.com/spreadsheets/d/1lkZSXS3HXTS_ZyPZytyIW0Keer_aKy8rr1_pxV2-fSs/pubhtml?gid=1097044156&single=true'; | ||
+ | selected_tags = read_checkbox_area() | ||
+ | everything = | ||
+ | "CAST([id] AS STRING), CAST([School] AS STRING), CAST([Section] AS STRING), CAST([Year] AS STRING), CAST([Wiki hyperlink] AS STRING), CAST([Award] AS STRING), CAST([Outreach Category] AS STRING), CAST([Outreach Project] AS STRING), CAST([Project Tag] AS STRING), CAST([Product] AS STRING), CAST([Product Description] AS STRING), CAST([Product Tag] AS STRING), CAST([Audience] AS STRING), CAST([Goal] AS STRING), CAST([Objectives] AS STRING), CAST([Data Type] AS STRING),CAST([Data] AS STRING), CAST([Reach] AS STRING), CAST([Analysis] AS STRING), CAST([References] AS STRING), CAST([Description] AS STRING)" | ||
+ | qString = 'SELECT * FROM outreach ' + outreach_db.compile_sql(selected_tags) | ||
+ | console.time(qString); | ||
+ | alasql(qString, [], callback = function(data) { | ||
+ | show_results(search_result = data); | ||
+ | console.log(data); | ||
+ | console.timeEnd(qString); | ||
+ | }); | ||
+ | } | ||
+ | |||
+ | function fulltext_search(str){ | ||
+ | show_results(search_result = fuse.search(str)) | ||
+ | } | ||
+ | function show_details(outreach_id) { | ||
+ | datastring = encodeURIComponent( | ||
+ | JSON.stringify( | ||
+ | outreach_db.get_by_id( | ||
+ | outreach_id | ||
+ | ) | ||
+ | ) | ||
+ | ); | ||
+ | console.log(decodeURIComponent(datastring)); | ||
+ | window.open('https://2017.igem.org/Team:William_and_Mary/Outreach_DB/Details?datastring=' + datastring); | ||
+ | } | ||
+ | var test; | ||
+ | |||
+ | function show_results(search_result) { | ||
+ | show_results.template = show_results.template || Handlebars.compile($('#search-results-template').html()) | ||
+ | //$('#search-results').html(show_results.template(search_result)); | ||
+ | $('#search-results').html(show_results.template(search_result)); | ||
+ | // bind click event to new links | ||
+ | $('.details-link').click( | ||
+ | function(e) { | ||
+ | clicked_outreach_id = e.target.getAttribute('outreach-id'); | ||
+ | show_details(clicked_outreach_id); | ||
+ | console.log(clicked_outreach_id); | ||
+ | return false; // return false to intercept event and prevent other things from handling link click | ||
+ | } | ||
+ | ) | ||
+ | } | ||
+ | |||
+ | function init_checkbox_area(tag_data) { | ||
+ | var checkbox_area_template_function = Handlebars.compile($("#checkbox-area-template").html()) | ||
+ | checkbox_area_html = checkbox_area_template_function(tag_data) | ||
+ | $('#checkbox-area').html(checkbox_area_html) | ||
+ | } | ||
+ | </script> | ||
</head> | </head> | ||
+ | |||
<body> | <body> | ||
− | + | <br></br> | |
− | + | <br></br> | |
− | + | <center><img src="https://static.igem.org/mediawiki/2017/4/41/T--William_and_Mary--Database383.jpeg" width=360/></center> | |
− | + | <br></br> | |
− | + | ||
− | </div> | + | |
+ | <!----start's here----> | ||
+ | |||
+ | <div class="container"> | ||
+ | <div class="row"> | ||
+ | <div class="col-lg-11" style='padding: top: 50px;font-size: 16px;'> | ||
+ | <form onsubmit="show_details(parseInt(document.getElementById('input-id').value, 10).toString()); return false"> | ||
+ | Quick ID Jump:<br /> <input type="number" name="id" id="input-id"> | ||
+ | <input type="submit" id="getid" value="Go"> | ||
+ | </form> | ||
+ | <form onsubmit="fulltext_search(document.getElementById('input-fuzzy').value); return false"> | ||
+ | Search:<br /> <input type="text" name="fuzzy" id="input-fuzzy"> | ||
+ | <input type="submit" id="get-fuzzy" value="Go"> | ||
+ | </div> | ||
+ | </div> | ||
+ | |||
+ | <center> | ||
+ | OR | ||
+ | </center> | ||
+ | |||
+ | <h2>Search By Tags:</h2> | ||
+ | <div id='checkbox-area' style='padding-top: 30px;'> | ||
+ | |||
+ | </div> | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | <div id='search-results'> | ||
+ | |||
+ | </div> | ||
+ | </div> | ||
</body> | </body> | ||
+ | |||
</html> | </html> | ||
+ | |||
+ | {{Team:William_and_Mary/FOOTER_SMALL}} |
Latest revision as of 02:46, 2 November 2017
Search By Tags: