Displaying differences for changeset
 
display as  

src/moplay/index.yaml

@@ -12,6 +12,12 @@
 
 - kind: Problem
   properties:
+  - name: is_public
+  - name: date_modified
+    direction: desc
+
+- kind: Problem
+  properties:
   - name: owner_id
   - name: date_modified
     direction: desc

src/moplay/js/multiobj.js

@@ -605,24 +605,11 @@
     })
 }
 
-// open the problems list dialog
-function openDialog(nextPage) {
+function queryProblemsList(listName, data, spinner, is_public) {
     "use strict";
 
-    // open the window
-    window.location.href = '#openModal';
-
-    // start spinner
-    var spinner = startSpinner('openModalInner');
-
-    // get the data to send
-    var cursor = $('#cursor');
-    var cursor_val = cursor.val();
-    var data = {
-        limit: 20
-    };
-    if (cursor_val !== '' && typeof nextPage !== 'undefined' && nextPage) {
-        data.cursor = cursor_val;
+    if (typeof is_public !== 'undefined' && is_public) {
+        data.is_public = true;
     }
 
     // get the problems list
@@ -634,7 +621,7 @@
         success: function(response) {
 
             // response.limit, response.cursor, response.more, response.problems
-            var problemsList = $('#problemsList');
+            var problemsList = $('#' + listName);
             problemsList.empty();
 
             if (typeof response.problems !== 'undefined') {
@@ -646,7 +633,7 @@
                 } else {
 
                     if (response.cursor !== '') {
-                        cursor.val(response.cursor);
+                        $('#cursor').val(response.cursor);
                     }
                     response.problems.forEach( function(problem) {
 
@@ -674,11 +661,38 @@
                 }
 
             } else {
+                alert('Uh Oh! We could not retrieve any problems!');
             }
 
             spinner.stop();
         }
     });
+
+
+}
+
+// open the problems list dialog
+function openDialog(nextPage) {
+    "use strict";
+
+    // open the window
+    window.location.href = '#openModal';
+
+    // start spinner
+    var spinner = startSpinner('openModalInner');
+
+    // get the data to send
+    var cursor = $('#cursor');
+    var cursor_val = cursor.val();
+    var data = {
+        limit: 20
+    };
+    if (cursor_val !== '' && typeof nextPage !== 'undefined' && nextPage) {
+        data.cursor = cursor_val;
+    }
+
+    queryProblemsList('problemsList', data, spinner);
+    queryProblemsList('publicProblemsList', data, spinner, true);
 }
 
 // run the code
@@ -952,3 +966,6 @@
     saveCode();
 });
 
+function setDefaultCode() {
+
+}
\ No newline at end of file

src/moplay/main.py

@@ -1,5 +1,5 @@
 import webapp2
-from models import Problem
+import json
 from google.appengine.ext import ndb
 from google.appengine.api import users
 from templates import env
@@ -19,9 +19,6 @@
         else:
             problem = None
 
-        # else:
-        #     problem = Problem.from_json(env.get_template('Kursawe.json').render())
-
         # get the user (login and logout urls)
         user = users.get_current_user()
         has_user = True if user else False
@@ -31,9 +28,11 @@
             user_url = users.create_login_url(self.request.uri)
 
         # render the page
+        comments = env.get_template('default_comments.txt').render()
         index = env.get_template('index.html').render(problem=problem,
                                                       has_user=has_user,
-                                                      user_url=user_url)
+                                                      user_url=user_url,
+                                                      comments=comments)
         self.response.write(index)
 
 

src/moplay/problems.py

@@ -110,16 +110,26 @@
     def get(self):
 
         user = users.get_current_user()
-        if user:
+        is_public = self.request.get('is_public').lower() == 'true'
+        if user or is_public:
 
+            # get parameters
             limit = int(self.request.get('limit', 5))
             cursor = self.request.get('cursor')
 
-            q = Problem.query(Problem.owner_id == user.user_id()).order(-Problem.date_modified)
+            # get query object
+            if is_public:
+                q = Problem.query(Problem.is_public == True).order(-Problem.date_modified)
+            else:
+                q = Problem.query(Problem.owner_id == user.user_id()).order(-Problem.date_modified)
+
+            # query the datastore with cursor if possible
             if cursor:
                 problems, next_cursor, more = q.fetch_page(limit, start_cursor=Cursor(urlsafe=cursor))
             else:
                 problems, next_cursor, more = q.fetch_page(limit)
+
+            # return json of problem list (just id, name, and date modified)
             self.response.write(json.dumps({
                 'limit': limit,
                 'cursor': next_cursor.urlsafe() if next_cursor else '',

src/moplay/stylesheets/main.css

@@ -366,6 +366,11 @@
     background-size: 29px;
 }
 
+.new-button {
+    background: #000000 url("/images/new_white.png") no-repeat center;
+    background-size: 22px;
+}
+
 .delete-button {
     margin-left: -10px;
     border-radius: 20px;

src/moplay/templates/index.html

@@ -35,6 +35,7 @@
         <div class="flex-container">
             <div class="param-row">
                 <div>
+                    <button id="new-code" onclick="if (confirm('Save Current?')) saveCode(); window.location.href = '/';" class="button-type new-button" title="Start New Problem"></button>
                     <button onclick="openDialog();" class="a-button-type open-button" title="Load Optimization Problems"></button>
                     <button onclick="runCode();" class="button-type play-button" title="Run Optimization"></button>
                     <button id="modal-button" onclick="window.location.href = '#chartModal';" class="button-type chart-button hidden" title="Show Graph or Table"></button>
@@ -66,7 +67,7 @@
             </div>
 
             <div class="param-row">
-                <input id="problem_public" type="checkbox" class="" onchange="console.log($('#problem_public').is(':checked')); if ($('#problem_public').is(':checked')) { $('#public_link').show(); } else { $('#public_link').hide(); }" {{ ("checked" if problem.is_public else '') if problem else '' }}/>
+                <input id="problem_public" type="checkbox" class="" onchange="if ($('#problem_public').is(':checked')) { $('#public_link').show(); } else { $('#public_link').hide(); }" {{ ("checked" if problem.is_public else '') if problem else '' }}/>
                 Make Public
             </div>
 
@@ -80,12 +81,12 @@
 
             <div class="param-row">
                 <div class="param-half">Max Evaluations:</div>
-                <input id="max_evals" type="text" placeholder="Maximum Evaluations" title="Maximum Evaluations" class="param-half margin-small" value="{{ problem.max_evals if problem else '' }}"/>
+                <input id="max_evals" type="text" placeholder="Maximum Evaluations" title="Maximum Evaluations" class="param-half margin-small" value="{{ problem.max_evals if problem else '10000' }}"/>
             </div>
 
             <div class="param-row">
                 <div class="param-half">Population Size:</div>
-                <input id="population" type="text" placeholder="Population Size" title="Population Size" class="param-half margin-small" value="{{ problem.population if problem else '' }}"/>
+                <input id="population" type="text" placeholder="Population Size" title="Population Size" class="param-half margin-small" value="{{ problem.population if problem else '50' }}"/>
             </div>
 
 
@@ -93,17 +94,17 @@
 
             <div class="param-row">
                 <div class="param-half">No. Decisions:</div>
-                <input id="nDecisions" type="text" placeholder="Number of Decision Variables" title="Number of Decision Variables" class="param-half margin-small" value="{{ problem.n_decisions if problem else '' }}"/>
+                <input id="nDecisions" type="text" placeholder="Number of Decision Variables" title="Number of Decision Variables" class="param-half margin-small" value="{{ problem.n_decisions if problem else '1' }}"/>
             </div>
 
             <div class="param-row">
                 <div class="param-half">No. Objectives:</div>
-                <input id="nObjectives" type="text" placeholder="Number of Objective Values" title="Number of Objective Values" class="param-half margin-small" value="{{ problem.n_objectives if problem else '' }}"/>
+                <input id="nObjectives" type="text" placeholder="Number of Objective Values" title="Number of Objective Values" class="param-half margin-small" value="{{ problem.n_objectives if problem else '1' }}"/>
             </div>
 
             <div class="param-row">
                 <div class="param-half">No. Constraints:</div>
-                <input id="nConstraints" type="text" placeholder="Number of Constraints" title="Number of Constraints" class="param-half margin-small" value="{{ problem.n_constraints if problem else '' }}"/>
+                <input id="nConstraints" type="text" placeholder="Number of Constraints" title="Number of Constraints" class="param-half margin-small" value="{{ problem.n_constraints if problem else '0' }}"/>
             </div>
 
             <h2 class="param-row">Variables</h2>
@@ -114,7 +115,7 @@
 
     </div>
 
-    <div id="editor">{{ (problem.code.strip() if problem else '')|safe  }}</div>
+    <div id="editor">{{ (problem.code.strip() if problem else comments)|safe  }}</div>
 
     <div id="chartModal" class="chartModal">
         <div id="chartModalInner">
@@ -162,10 +163,14 @@
 
     // variables
     var variables = {{ problem.vars_json()|safe }};
+    {% else %}
+
+    // variables
+    var variables = [{'type': 'real', 'lower': 0.0, 'upper': 10.0, 'nbits': 0.0}];
+    {% endif %}
 
     // populate the select elements
-    fillVariables('variables', variables, "{{ problem.method }}");
-    {% endif %}
+    fillVariables('variables', variables, "{{ problem.method if problem else 'NSGAII' }}");
 
     // set event listeners
     var ndec = document.getElementById('nDecisions');