Commit 6f9f9cb3 by Arturo Montejo Ráez

refactorización de sesiones lista

parents c8dff581 92eba8c1
Showing with 335 additions and 478 deletions
...@@ -10,7 +10,7 @@ android { ...@@ -10,7 +10,7 @@ android {
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
resValue "string", "db_name", "PCB.db" resValue "string", "db_name", "PCB.db"
resValue "integer", "db_version", "3" resValue "integer", "db_version", "4"
resValue "string", "app_version", "0.1" resValue "string", "app_version", "0.1"
resValue "string", "core_vocabulary", "core_vocabulary" resValue "string", "core_vocabulary", "core_vocabulary"
resValue "string", "apk", "to_be_set_in_subproject" resValue "string", "apk", "to_be_set_in_subproject"
......
...@@ -215,7 +215,7 @@ public class RestapiWrapper { ...@@ -215,7 +215,7 @@ public class RestapiWrapper {
} }
} }
Log.e(this.getClass().getCanonicalName(),"POST-->"+surl+" "+request_method+" j"+json_params+" param"+sparams);
//Send request //Send request
DataOutputStream wr = new DataOutputStream ( DataOutputStream wr = new DataOutputStream (
urlConnection.getOutputStream ()); urlConnection.getOutputStream ());
......
...@@ -54,7 +54,7 @@ public class Device extends SQLiteOpenHelper { ...@@ -54,7 +54,7 @@ public class Device extends SQLiteOpenHelper {
*/ */
public Device(Context context, CursorFactory factory, int version) { public Device(Context context, CursorFactory factory, int version) {
super(context, DeviceHelper.getDBName(context), factory, DeviceHelper.getDBVersion(context)); super(context, DeviceHelper.getDBName(context), factory, version);
if (DeviceHelper.force_create(context)) { if (DeviceHelper.force_create(context)) {
Log.i(this.getClass().getCanonicalName(),"Forcing create new Database "+DeviceHelper.getDBName(context)+" v."+ DeviceHelper.getDBVersion(context)); Log.i(this.getClass().getCanonicalName(),"Forcing create new Database "+DeviceHelper.getDBName(context)+" v."+ DeviceHelper.getDBVersion(context));
context.deleteDatabase(DeviceHelper.getDBName(context)); context.deleteDatabase(DeviceHelper.getDBName(context));
...@@ -354,11 +354,10 @@ public class Device extends SQLiteOpenHelper { ...@@ -354,11 +354,10 @@ public class Device extends SQLiteOpenHelper {
Cursor cursor = db.query("picto", new String[]{"(SELECT MIN(id) FROM picto) AS MIN"}, null, null, null, null, null, "1"); Cursor cursor = db.query("picto", new String[]{"(SELECT MIN(id) FROM picto) AS MIN"}, null, null, null, null, null, "1");
cursor.moveToFirst(); cursor.moveToFirst();
next_key=cursor.getInt(cursor.getColumnIndex("MIN"))-1; next_key=cursor.getInt(cursor.getColumnIndex("MIN"))-1;
if (next_key>=0) next_key=-1;
cursor.close(); cursor.close();
db.close(); db.close();
return next_key; return next_key>=0 ? -1 : next_key;
} }
......
...@@ -155,7 +155,7 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -155,7 +155,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
cursor.moveToFirst(); cursor.moveToFirst();
if (cursor.getCount()>0) do{ if (cursor.getCount()>0) do{
Picto picto = new Picto(cursor.getInt(1), cursor.getString(2), cursor.getString(3), cursor.getString(4)); Picto picto = new Picto(cursor.getInt(1), cursor.getString(2), cursor.getString(3), cursor.getString(4));
vocabulary.loadPicto(picto); vocabulary.addPicto(picto);
}while (cursor.moveToNext()); }while (cursor.moveToNext());
cursor.close(); cursor.close();
db.close(); db.close();
...@@ -204,7 +204,7 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -204,7 +204,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
* @param picto added to the Student collection * @param picto added to the Student collection
* @see com.yottacode.pictogram.dao.Picto * @see com.yottacode.pictogram.dao.Picto
*/ */
public void addPicto(Picto picto) { public void savePicto(Picto picto) {
int id_stu = this.getCurrentUser().get_id_stu(); int id_stu = this.getCurrentUser().get_id_stu();
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
ContentValues values=new ContentValues(6); ContentValues values=new ContentValues(6);
......
...@@ -2,8 +2,6 @@ package com.yottacode.pictogram.dao; ...@@ -2,8 +2,6 @@ package com.yottacode.pictogram.dao;
import android.graphics.Color; import android.graphics.Color;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log; import android.util.Log;
import com.yottacode.pictogram.action.VocabularyAction; import com.yottacode.pictogram.action.VocabularyAction;
...@@ -14,8 +12,6 @@ import com.yottacode.pictogram.tools.PCBcontext; ...@@ -14,8 +12,6 @@ import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.Serializable;
/** /**
* A object which represents a pictogram * A object which represents a pictogram
...@@ -25,7 +21,22 @@ import java.io.Serializable; ...@@ -25,7 +21,22 @@ import java.io.Serializable;
*/ */
public class Picto extends Img { public class Picto extends Img {
private static final String LOG_TAG =Img.class.getName();
public static final int STUPICTO_NULL = -1;
public int get_stupicto_id() {
int stupicto_id;
try {
stupicto_id=this.attributes.getInt(JSON_ATTTRS.STUPICTO_ID);
} catch (JSONException e) {
e.printStackTrace();
stupicto_id=STUPICTO_NULL ;
}
return stupicto_id;
}
public final static class JSON_ATTTRS { public final static class JSON_ATTTRS {
public static String STUPICTO_ID = "id";
public static String CATEGORY = "id_cat"; public static String CATEGORY = "id_cat";
public static String COLUMN = "coord_x"; public static String COLUMN = "coord_x";
public static String ROW = "coord_y"; public static String ROW = "coord_y";
...@@ -75,11 +86,11 @@ public class Picto extends Img { ...@@ -75,11 +86,11 @@ public class Picto extends Img {
try { try {
this.attributes=new JSONObject(p.attributes.toString()); this.attributes=new JSONObject(p.attributes.toString());
} catch (JSONException e) { } catch (JSONException e) {
Log.e(this.getClass().getCanonicalName(),e.getMessage()); Log.e(LOG_TAG,e.getMessage());
} }
translation=new String(p.get_translation()); translation=new String(p.get_translation());
} }
public Picto(int id, String url, String translation, int cat, int row, int column, int freeRow, int freeColumn) throws JSONException { public Picto(int id, String url, String translation, int cat, int row, int column, int freeRow, int freeColumn, int stupicto_id) throws JSONException {
this(id, url, translation, new JSONObject() this(id, url, translation, new JSONObject()
.put(JSON_ATTTRS.CATEGORY, cat) .put(JSON_ATTTRS.CATEGORY, cat)
.put(JSON_ATTTRS.COLUMN, column) .put(JSON_ATTTRS.COLUMN, column)
...@@ -87,7 +98,8 @@ public class Picto extends Img { ...@@ -87,7 +98,8 @@ public class Picto extends Img {
.put(JSON_ATTTRS.FREE_ROW, freeRow) .put(JSON_ATTTRS.FREE_ROW, freeRow)
.put(JSON_ATTTRS.FREE_COLUMN, freeColumn) .put(JSON_ATTTRS.FREE_COLUMN, freeColumn)
.put(JSON_ATTTRS.STATUS, JSON_ATTTR_STATUS_VALUES.ENABLED) .put(JSON_ATTTRS.STATUS, JSON_ATTTR_STATUS_VALUES.ENABLED)
.put(JSON_ATTTRS.LEGEND,JSON_ATTTR_LEGEND_VALUES.NONE)); .put(JSON_ATTTRS.LEGEND,JSON_ATTTR_LEGEND_VALUES.NONE)
.put(JSON_ATTTRS.STUPICTO_ID,stupicto_id));
} }
public Picto(int id, String url,String translation, String attributes) throws JSONException { public Picto(int id, String url,String translation, String attributes) throws JSONException {
this(id, url, translation, new JSONObject(attributes)); this(id, url, translation, new JSONObject(attributes));
...@@ -102,7 +114,7 @@ public class Picto extends Img { ...@@ -102,7 +114,7 @@ public class Picto extends Img {
if (this.attributes.get(JSON_ATTTRS.CATEGORY)==null) if (this.attributes.get(JSON_ATTTRS.CATEGORY)==null)
this.attributes.put(JSON_ATTTRS.CATEGORY, Picto.NO_CATEGORY); this.attributes.put(JSON_ATTTRS.CATEGORY, Picto.NO_CATEGORY);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(this.getClass().getName(), e.toString()); Log.e(LOG_TAG, e.toString());
} }
} }
...@@ -282,6 +294,7 @@ public class Picto extends Img { ...@@ -282,6 +294,7 @@ public class Picto extends Img {
legend=this.attributes.getString(JSON_ATTTRS.LEGEND); legend=this.attributes.getString(JSON_ATTTRS.LEGEND);
} catch (JSONException e) { } catch (JSONException e) {
legend=JSON_ATTTR_LEGEND_VALUES.NONE; // By default legend=JSON_ATTTR_LEGEND_VALUES.NONE; // By default
Log.e(LOG_TAG," Error getting legend:"+e.getMessage());
} }
return legend.equalsIgnoreCase("null") ? JSON_ATTTR_LEGEND_VALUES.NONE : legend; return legend.equalsIgnoreCase("null") ? JSON_ATTTR_LEGEND_VALUES.NONE : legend;
} }
...@@ -363,36 +376,14 @@ public class Picto extends Img { ...@@ -363,36 +376,14 @@ public class Picto extends Img {
return "(" + get_id() + ") - ["+ get_row() +","+ get_column()+"]" + get_translation() + "(Cat: " + get_category() + ") - " + get_url() + " --- " + get_json_attrs(); return "(" + get_id() + ") - ["+ get_row() +","+ get_column()+"]" + get_translation() + "(Cat: " + get_category() + ") - " + get_url() + " --- " + get_json_attrs();
} }
/**
* modify locally the status of the picto
* @return true if current status is enabled. False in other case.
*/
/*public boolean alter_status() {
String status=is_enabled() ? JSON_ATTTR_STATUS_VALUES.DISABLED
: is_disabled() ? JSON_ATTTR_STATUS_VALUES.INVISIBLE
: JSON_ATTTR_STATUS_VALUES.ENABLED;
Log.i(this.getClass().getCanonicalName(),"Picto id. "+get_id()+" status enabled/disabled modified to "+is_enabled());
try {
this.attributes.put(JSON_ATTTRS.STATUS, status);
set_local_status(true);
if (!is_local()) {
new PictoUploader(this).uploadState();
PCBcontext.getActionLog().log(new VocabularyAction(VocabularyAction.ALTERATTRS, this));
}
} catch (JSONException e) {
e.printStackTrace();
Log.e(this.getClass().getCanonicalName(),e.getMessage());
}
return is_enabled();
}
*/
/** /**
* modify locally the status of the picto * modify locally the status of the picto
* @param status the status that u press on the menu * @param status the status that u press on the menu
* @return true if current status is enabled. False in other case. * @return true if current status is enabled. False in other case.
*/ */
public boolean alter_status(String status) { public boolean alter_status(String status) {
Log.i(this.getClass().getCanonicalName(),"Picto id. "+get_id()+" status enabled/disabled modified to "+is_enabled()); Log.i(LOG_TAG,"Picto id. "+get_id()+" status enabled/disabled modified to "+is_enabled());
try { try {
this.attributes.put(JSON_ATTTRS.STATUS, status); this.attributes.put(JSON_ATTTRS.STATUS, status);
set_local_status(true); set_local_status(true);
...@@ -402,7 +393,7 @@ public class Picto extends Img { ...@@ -402,7 +393,7 @@ public class Picto extends Img {
} }
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
Log.e(this.getClass().getCanonicalName(),e.getMessage()); Log.e(LOG_TAG,e.getMessage());
} }
return is_enabled(); return is_enabled();
} }
...@@ -425,7 +416,7 @@ public class Picto extends Img { ...@@ -425,7 +416,7 @@ public class Picto extends Img {
PCBcontext.getPcbdb().modifyPicto(this.get_id(), this.get_json_attrs()); PCBcontext.getPcbdb().modifyPicto(this.get_id(), this.get_json_attrs());
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
Log.e(this.getClass().getCanonicalName(), e.getMessage()); Log.e(LOG_TAG, e.getMessage());
} }
else { else {
...@@ -433,4 +424,5 @@ public class Picto extends Img { ...@@ -433,4 +424,5 @@ public class Picto extends Img {
PCBcontext.getPcbdb().modifyPicto(this.get_id(), this.get_json_attrs()); PCBcontext.getPcbdb().modifyPicto(this.get_id(), this.get_json_attrs());
} }
} }
} }
...@@ -90,6 +90,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -90,6 +90,7 @@ public class Vocabulary implements Iterable<Picto> {
try{ try{
String uri=args.getJSONObject("picto").getString("uri"); String uri=args.getJSONObject("picto").getString("uri");
JSONObject attrs_picto = args.getJSONObject("attributes"); JSONObject attrs_picto = args.getJSONObject("attributes");
attrs_picto.put(Picto.JSON_ATTTRS.STUPICTO_ID,args.getInt("id"));
String text= attrs_picto.getString("expression"); String text= attrs_picto.getString("expression");
addPicto(new Picto(picto_id, uri, text, attrs_picto),ImgDownloader.tsource.remote); addPicto(new Picto(picto_id, uri, text, attrs_picto),ImgDownloader.tsource.remote);
...@@ -135,7 +136,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -135,7 +136,7 @@ public class Vocabulary implements Iterable<Picto> {
Log.i(this.getClass().getCanonicalName(), "Picto status modified while offline. Picto translation: '" + Log.i(this.getClass().getCanonicalName(), "Picto status modified while offline. Picto translation: '" +
picto.get_translation() + "', id:" + picto.get_id() + " Local status?" + picto.local_status()); picto.get_translation() + "', id:" + picto.get_id() + " Local status?" + picto.local_status());
} }
if (picto.is_local()) //id<0 iif it is a local id if (picto.is_local())
try { try {
Log.i(this.getClass().getCanonicalName(), "Picto added while offline. Picto translation: '" + Log.i(this.getClass().getCanonicalName(), "Picto added while offline. Picto translation: '" +
picto.get_translation() + "', id:" + picto.get_id() + " Local status?" + picto.local_status()); picto.get_translation() + "', id:" + picto.get_id() + " Local status?" + picto.local_status());
...@@ -172,17 +173,18 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -172,17 +173,18 @@ public class Vocabulary implements Iterable<Picto> {
final String juri = "uri"; final String juri = "uri";
final String jattributes = "attributes"; final String jattributes = "attributes";
final String jexpression = "expression"; final String jexpression = "expression";
final String jexpression_text = "text";
Picto[] pictos = new Picto[result.length()]; Picto[] pictos = new Picto[result.length()];
JSONObject picto = null, attributes = null; JSONObject picto, attributes ;
String expression; String expression;
JSONObject ojpicto=null; JSONObject stupicto=null;
try { try {
for (int i=0; i < result.length(); i++) { for (int i=0; i < result.length(); i++) {
ojpicto=result.getJSONObject(i); stupicto=result.getJSONObject(i);
picto = ojpicto.getJSONObject(jpicto); picto = stupicto.getJSONObject(jpicto);
attributes = ojpicto.getJSONObject(jattributes); attributes = stupicto.getJSONObject(jattributes);
attributes.put(Picto.JSON_ATTTRS.STUPICTO_ID,stupicto.get(jid));
expression = attributes.getString(jexpression); expression = attributes.getString(jexpression);
pictos[i] = new Picto(picto.getInt(jid), pictos[i] = new Picto(picto.getInt(jid),
picto.getString(juri), picto.getString(juri),
...@@ -197,7 +199,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -197,7 +199,7 @@ public class Vocabulary implements Iterable<Picto> {
StackTraceElement traces[] = e.getStackTrace(); StackTraceElement traces[] = e.getStackTrace();
for (StackTraceElement s: traces) for (StackTraceElement s: traces)
Log.e(s.getClassName()+"."+s.getFileName()+"."+s.getLineNumber(),s.toString()); Log.e(s.getClassName()+"."+s.getFileName()+"."+s.getLineNumber(),s.toString());
Log.e(this.getClass().getName(), " Picto JSON error from server: " + ojpicto.toString()); Log.e(this.getClass().getName(), " Picto JSON error from server: " + stupicto.toString());
this.error(new RestapiWrapper.HTTPException("JSON Error:"+e.getMessage(),-1)); this.error(new RestapiWrapper.HTTPException("JSON Error:"+e.getMessage(),-1));
} }
} }
...@@ -264,9 +266,9 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -264,9 +266,9 @@ public class Vocabulary implements Iterable<Picto> {
ImgDownloader downloader = new ImgDownloader(PCBcontext.getContext(), imgListener,source); ImgDownloader downloader = new ImgDownloader(PCBcontext.getContext(), imgListener,source);
downloader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, imgs); downloader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, imgs);
loadPicto(pic); addPicto(pic);
PCBcontext.getPcbdb().addPicto(pic); PCBcontext.getPcbdb().savePicto(pic);
} }
public void setImgDownloaderListener(ImgDownloader.iImgDownloaderListener listener) { public void setImgDownloaderListener(ImgDownloader.iImgDownloaderListener listener) {
...@@ -289,6 +291,15 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -289,6 +291,15 @@ public class Vocabulary implements Iterable<Picto> {
return index; return index;
} }
private Picto find_picto(int pic_cat, int row,int column) {
LinkedList<Picto> pictos_cat=this.pictos.get(pic_cat);
Picto picto=null;
for (int i=0; i<pictos_cat.size() && picto==null; i++)
if (pictos_cat.get(i).get_column()==column && pictos_cat.get(i).get_row()==row) picto=pictos_cat.get(i);
return picto;
}
public Picto get_picto(int pic_cat, int pic_id) { public Picto get_picto(int pic_cat, int pic_id) {
Picto picto=null; Picto picto=null;
LinkedList<Picto> pictos_cat=this.pictos.get(pic_cat); LinkedList<Picto> pictos_cat=this.pictos.get(pic_cat);
...@@ -335,8 +346,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -335,8 +346,7 @@ public class Vocabulary implements Iterable<Picto> {
* @param picto * @param picto
* @seealso com.yottacode.pictogram.dao.PCBDBHelper.getStudentVocabulary * @seealso com.yottacode.pictogram.dao.PCBDBHelper.getStudentVocabulary
*/ */
public void loadPicto(Picto picto) { public void addPicto(Picto picto) {
Log.i(LOG_TAG, "load picto "+picto.get_translation());
LinkedList<Picto> pictos_cat; LinkedList<Picto> pictos_cat;
if (this.pictos.containsKey(picto.get_category())) if (this.pictos.containsKey(picto.get_category()))
pictos_cat = pictos.get(picto.get_category()); pictos_cat = pictos.get(picto.get_category());
...@@ -389,10 +399,19 @@ Log.i(LOG_TAG, "load picto "+picto.get_translation()); ...@@ -389,10 +399,19 @@ Log.i(LOG_TAG, "load picto "+picto.get_translation());
* It saves locally a new picto obtained from the PCB * It saves locally a new picto obtained from the PCB
*/ */
public Picto saveLocalPicto(String url, String exp, int cat, int coord_x, int coord_y, int free_category_coord_x, int free_category_coord_y, final iLocalPicto listener) { public Picto saveLocalPicto(String url, String exp, int cat, int coord_x, int coord_y, int free_category_coord_x, int free_category_coord_y, final iLocalPicto listener) {
int id= PCBcontext.getDevice().getNextLocalPictoID();
Picto prev_picto=find_picto(cat, coord_x,coord_y); //¿estamos reemplazanddo un picto que ya existe?
if (prev_picto!=null) { //El picto ya existe
removePicto(prev_picto.get_category(),prev_picto.get_id()); //borramos el picto local actual
Log.i(LOG_TAG,"Picto "+exp+" already exists. Previous local picto "+prev_picto.get_id()+" is deleted.");
}
int id=PCBcontext.getDevice().getNextLocalPictoID();
final Picto picto[]=new Picto[1]; final Picto picto[]=new Picto[1];
try { try {
picto[0] = new Picto(id, url, exp, cat, coord_x, coord_y, free_category_coord_x, free_category_coord_y); picto[0] = new Picto(id, url, exp, cat, coord_x, coord_y, free_category_coord_x, free_category_coord_y, prev_picto!=null ? prev_picto.get_stupicto_id() : Picto.STUPICTO_NULL);
addPicto(picto[0], ImgDownloader.tsource.local, new ImgDownloader.iImgDownloaderListener() { addPicto(picto[0], ImgDownloader.tsource.local, new ImgDownloader.iImgDownloaderListener() {
@Override @Override
public void loadComplete() { public void loadComplete() {
......
...@@ -45,6 +45,7 @@ public class VocabularyTalk implements Emitter.Listener { ...@@ -45,6 +45,7 @@ public class VocabularyTalk implements Emitter.Listener {
Log.i(LOG_TAG, "raw Received message " +msg.toString()); Log.i(LOG_TAG, "raw Received message " +msg.toString());
String action = msg.getString(param_action).toLowerCase(); String action = msg.getString(param_action).toLowerCase();
JSONObject stu_picto= msg.getJSONObject(param_attributes).getJSONObject(param_stu_picto); JSONObject stu_picto= msg.getJSONObject(param_attributes).getJSONObject(param_stu_picto);
int stupicto_id=stu_picto.getInt(param_picto_id);
JSONObject attrs_stu_picto = stu_picto.optJSONObject(param_attributes); JSONObject attrs_stu_picto = stu_picto.optJSONObject(param_attributes);
JSONObject picto_stupicto = stu_picto.optJSONObject(param_picto); JSONObject picto_stupicto = stu_picto.optJSONObject(param_picto);
int picto_id = picto_stupicto.getInt(param_picto_id); int picto_id = picto_stupicto.getInt(param_picto_id);
......
...@@ -8,6 +8,7 @@ import com.yottacode.net.SSLDummyContext; ...@@ -8,6 +8,7 @@ import com.yottacode.net.SSLDummyContext;
import com.yottacode.pictogram.R; import com.yottacode.pictogram.R;
import com.yottacode.pictogram.action.ActionLog; import com.yottacode.pictogram.action.ActionLog;
import com.yottacode.pictogram.dao.Device; import com.yottacode.pictogram.dao.Device;
import com.yottacode.pictogram.dao.DeviceHelper;
import com.yottacode.pictogram.dao.PCBDBHelper; import com.yottacode.pictogram.dao.PCBDBHelper;
import com.yottacode.pictogram.dao.User; import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.grammar.Vocabulary; import com.yottacode.pictogram.grammar.Vocabulary;
...@@ -38,7 +39,7 @@ public final class PCBcontext { ...@@ -38,7 +39,7 @@ public final class PCBcontext {
if (!init) { if (!init) {
init = true; init = true;
context = c; context = c;
device = new Device(c, null, 2); device = new Device(c, null, DeviceHelper.getDBVersion(context));
activityContext=null; activityContext=null;
SSLDummyContext.init(context.getResources().getBoolean(R.bool.ssl_connect)); SSLDummyContext.init(context.getResources().getBoolean(R.bool.ssl_connect));
service = new NetService(context.getResources().getInteger(R.integer.netservice_timing),listener); service = new NetService(context.getResources().getInteger(R.integer.netservice_timing),listener);
......
package com.yottacode.pictogram.tabletlibrary.gui.communicator; package com.yottacode.pictogram.tabletlibrary.gui.communicator;
import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -64,79 +60,6 @@ public class PictoItemViewGenerator { ...@@ -64,79 +60,6 @@ public class PictoItemViewGenerator {
} }
/**
* @param context
* @param bitmap Bitmap to add the legend and rescale
* @param picto
* @return the bitmap scaled and with the legend or without changes
*/
private static Bitmap set_legend(Context context,Bitmap bitmap,Picto picto) {
{
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
int width = bitmap.getWidth(); //Ancho original
int height = bitmap.getHeight(); //Alto original
//String texto = format_legend(picto,MAX_LINE_LENGTH);
/*if(picto.get_legend().equals("normal")) { //Normal legend
android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();
if (bitmapConfig == null) {
bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
}
bitmap = bitmap.copy(bitmapConfig, true);
Canvas canvas = new Canvas(bitmap);
Bitmap bm = Bitmap.createScaledBitmap(bitmap, width / 2, height / 2, false);
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); //Poner en blanco el bitmap original para dibujar encima
canvas.drawBitmap(bm, 25, 0, paint);
TextView textView = new TextView(context);
textView.layout(0, 50, 100, 100);
textView.setPadding(0, 0, 0, 0);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 13);
textView.setTextColor(Color.BLACK);
textView.setBackgroundColor(Color.WHITE);
textView.setWidth(100);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setMaxLines(4);
textView.setText(texto);
textView.setDrawingCacheEnabled(true);
canvas.drawBitmap(textView.getDrawingCache(), 0, 50, null);
}else{*/
//Only legend
android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();
if (bitmapConfig == null) {
bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
}
bitmap = bitmap.copy(bitmapConfig, true);
Canvas canvas = new Canvas(bitmap);
paint.setColor(Color.WHITE);
canvas.drawRect(0,0,100,100,paint);
TextView textView = new TextView(context);
textView.layout(0, 0, 100, 100);
textView.setPadding(0, 0, 0, 0);
textView.setTextSize(PCBcontext.getPcbdb().getCurrentUser().is_picto_size_big() ? 13 : 11);
textView.setTextColor(Color.rgb(0,0,0));
textView.setWidth(100);
textView.setGravity(Gravity.CENTER);
textView.setMaxLines(3);
//textView.setText(texto);
textView.setDrawingCacheEnabled(true);
canvas.drawBitmap(textView.getDrawingCache(), 0, 25, null);
}
//}
return bitmap;
}
public static View getPictoView(Picto picto, View convertView, ViewGroup parent) { public static View getPictoView(Picto picto, View convertView, ViewGroup parent) {
return getPictoView(picto, convertView, parent, false); return getPictoView(picto, convertView, parent, false);
......
package com.yottacode.pictogram.tabletlibrary.gui.communicator; package com.yottacode.pictogram.tabletlibrary.gui.communicator;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
...@@ -53,7 +45,7 @@ public class PictoMenu { ...@@ -53,7 +45,7 @@ public class PictoMenu {
* @param col * @param col
* @param expression * @param expression
*/ */
public void createMenuForNewPicto(final int row, final int col, final int cat, final String expression, boolean is_picto_big) { public void createMenuForNewPicto(final int row, final int col, final int cat, final String expression) {
ll = new RelativeLayout(PCBcontext.getContext()); ll = new RelativeLayout(PCBcontext.getContext());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
...@@ -66,58 +58,20 @@ public class PictoMenu { ...@@ -66,58 +58,20 @@ public class PictoMenu {
int centerX = activity.getResources().getDisplayMetrics().widthPixels/2; int centerX = activity.getResources().getDisplayMetrics().widthPixels/2;
int centerY = activity.getResources().getDisplayMetrics().heightPixels/2; int centerY = activity.getResources().getDisplayMetrics().heightPixels/2;
if(!is_picto_big){
centerY += 100;
detail.setMaxWidth(90);
}else{
centerY += 135;
detail.setMaxWidth(115);
}
PieMenu = new RadialMenuWidget(PCBcontext.getContext()); PieMenu = new RadialMenuWidget(PCBcontext.getContext());
PieMenu.setAnimationSpeed(0L); PieMenu.setAnimationSpeed(0L);
PieMenu.setCenterLocation(centerX - (PieMenu.getcRadius()*2) - 50, centerY-(PieMenu.getcRadius()*2)); PieMenu.setCenterLocation(centerX, centerY+(PieMenu.getcRadius()*2));
PieMenu.setIconSize(20,35); //Tamaño del icono PieMenu.setIconSize(20,35); //Tamaño del icono
Picto picto = null;
PieMenu.setCenterCircle(new Close()); PieMenu.setCenterCircle(new Close());
PieMenu.addMenuEntry(new newPickFromCamera(row,col,cat,expression)); PieMenu.addMenuEntry(new newPickFromCamera(row,col,cat,expression));
PieMenu.addMenuEntry(new newPickFromGallery(row,col,cat,expression)); PieMenu.addMenuEntry(new newPickFromGallery(row,col,cat,expression));
ll.addView(PieMenu); ll.addView(PieMenu);
detail.setImageResource(R.color.black);
detail.setMaxWidth(96);
detail.setMaxHeight(96);
detail.setX(centerX+10);
detail.setY(centerY - 96);
ll.addView(detail);
/*final String[] items = new String[]{activity.getString(R.string.dialogCamera), activity.getString(R.string.dialogGallery)};
ArrayAdapter<String> adapter = new ArrayAdapter<>(activity, android.R.layout.select_dialog_item, items);
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(activity.getString(R.string.dialogTitle));
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
addPicto(row,col,cat,expression,item);
}
});
builder.setNegativeButton(activity.getString(R.string.dialogCancel), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
final AlertDialog dialog = builder.create();
dialog.show();*/
} }
...@@ -146,66 +100,6 @@ public class PictoMenu { ...@@ -146,66 +100,6 @@ public class PictoMenu {
} }
/**
* Función para la selección de una foto del carrete
*
* @param requestCode
* @param resultCode
* @param data
*/
/*public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
String selectedImagePath;
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
int row = activity.getIntent().getIntExtra(Picto.JSON_ATTTRS.ROW, -1);
int col = activity.getIntent().getIntExtra(Picto.JSON_ATTTRS.COLUMN, -1);
int freeRow = activity.getIntent().getIntExtra(Picto.JSON_ATTTRS.FREE_ROW, -1);
int freeColumn = activity.getIntent().getIntExtra(Picto.JSON_ATTTRS.FREE_COLUMN, -1);
Log.i(activity.getClass().getCanonicalName(), "0 Picto x y " + " " + row + " " + col);
activity.getIntent().removeExtra(Picto.JSON_ATTTRS.ROW);
activity.getIntent().removeExtra(Picto.JSON_ATTTRS.COLUMN);
activity.getIntent().removeExtra(Picto.JSON_ATTTRS.FREE_ROW);
activity.getIntent().removeExtra(Picto.JSON_ATTTRS.FREE_COLUMN);
//chooseTextAndSavePicto(selectedImagePath, row, col, freeRow, freeColumn);
}
}
}*/
/**
* Función para la selección de una foto del carrete
*
* @param uri
* @return
*/
static public String getPath(Uri uri) {
if (uri == null) {
return null;
}
// this will only work for images selected from gallery
String[] projection = {MediaStore.Images.Media.DATA};
Cursor cursor = PCBcontext.getContext().getContentResolver().query(uri, projection, null, null, null);
if (cursor != null) {
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
return uri.getPath();
}
/**Function for build a radial menu /**Function for build a radial menu
* *
* @param is_picto_big * @param is_picto_big
...@@ -243,7 +137,7 @@ public class PictoMenu { ...@@ -243,7 +137,7 @@ public class PictoMenu {
PieMenu.addMenuEntry(new UnlockPictoMenu(picto)); PieMenu.addMenuEntry(new UnlockPictoMenu(picto));
PieMenu.addMenuEntry(new DisablePictoMenu(picto)); PieMenu.addMenuEntry(new DisablePictoMenu(picto));
PieMenu.addMenuEntry(new SetInvisibleMenu(picto)); PieMenu.addMenuEntry(new SetInvisibleMenu(picto));
PieMenu.addMenuEntry(new EditMenu(picto)); if (!picto.is_category()) PieMenu.addMenuEntry(new EditMenu(picto));
ll.addView(PieMenu); ll.addView(PieMenu);
...@@ -286,7 +180,7 @@ public class PictoMenu { ...@@ -286,7 +180,7 @@ public class PictoMenu {
} }
public String getName() { return "disable"; } public String getName() { return "disable"; }
public String getLabel() { return null; } public String getLabel() { return null; }
public int getIcon() { return android.R.drawable.ic_delete; } public int getIcon() { return R.drawable.disabled_picto; }
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; } public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated() public void menuActiviated()
{ {
...@@ -351,7 +245,7 @@ public class PictoMenu { ...@@ -351,7 +245,7 @@ public class PictoMenu {
} }
public String getName() { return "edit"; } public String getName() { return "edit"; }
public String getLabel() { return null; } public String getLabel() { return null; }
public int getIcon() { return android.R.drawable.ic_menu_edit; } public int getIcon() { return R.drawable.edit_picture; }
private List<RadialMenuWidget.RadialMenuEntry> children; private List<RadialMenuWidget.RadialMenuEntry> children;
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return children; } public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return children; }
public void menuActiviated() public void menuActiviated()
...@@ -373,7 +267,7 @@ public class PictoMenu { ...@@ -373,7 +267,7 @@ public class PictoMenu {
} }
public String getName() { return "editText"; } public String getName() { return "editText"; }
public String getLabel() { return null; } public String getLabel() { return null; }
public int getIcon() { return android.R.drawable.ic_menu_camera; } public int getIcon() { return R.drawable.camera; }
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; } public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated() public void menuActiviated()
{ {
...@@ -393,7 +287,7 @@ public class PictoMenu { ...@@ -393,7 +287,7 @@ public class PictoMenu {
} }
public String getName() { return "editImage"; } public String getName() { return "editImage"; }
public String getLabel() { return null; } public String getLabel() { return null; }
public int getIcon() { return android.R.drawable.ic_menu_gallery; } public int getIcon() { return R.drawable.gallery; }
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; } public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated() public void menuActiviated()
{ {
...@@ -416,7 +310,7 @@ public class PictoMenu { ...@@ -416,7 +310,7 @@ public class PictoMenu {
} }
public String getName() { return ""; } public String getName() { return ""; }
public String getLabel() { return null; } public String getLabel() { return null; }
public int getIcon() { return android.R.drawable.ic_menu_camera; } public int getIcon() { return R.drawable.camera; }
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; } public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated() public void menuActiviated()
{ {
...@@ -440,7 +334,7 @@ public class PictoMenu { ...@@ -440,7 +334,7 @@ public class PictoMenu {
} }
public String getName() { return ""; } public String getName() { return ""; }
public String getLabel() { return null; } public String getLabel() { return null; }
public int getIcon() { return android.R.drawable.ic_menu_gallery; } public int getIcon() { return R.drawable.gallery; }
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; } public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated() public void menuActiviated()
{ {
......
...@@ -841,7 +841,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -841,7 +841,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
if (p == null) { if (p == null) {
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria // No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria
if (getCurrentCategory() != null || !PCBcontext.getPcbdb().getCurrentUser().has_categories()) { if (getCurrentCategory() != null || !PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
new PictoMenu(PictogramActivity.this).createMenuForNewPicto(position % maxColumns, (int) (position / maxColumns), currentCategory.get_id(),null,PCBcontext.getPcbdb().getCurrentUser().is_picto_size_big()); new PictoMenu(PictogramActivity.this).createMenuForNewPicto(position % maxColumns, (int) (position / maxColumns), currentCategory.get_id(),null);
} else } else
Toast.makeText(PictogramActivity.this, PictogramActivity.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show(); Toast.makeText(PictogramActivity.this, PictogramActivity.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show();
...@@ -1093,7 +1093,6 @@ protected void showOnlyTape(boolean onlyTape) { ...@@ -1093,7 +1093,6 @@ protected void showOnlyTape(boolean onlyTape) {
*/ */
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
Log.e(LOG_TAG,"CTSA prec (onACR)"+requestCode+" "+resultCode);
int cat = getIntent().getIntExtra("cat", -1); int cat = getIntent().getIntExtra("cat", -1);
......
...@@ -36,16 +36,16 @@ ...@@ -36,16 +36,16 @@
android:layout_marginTop="@dimen/activity_vertical_margin" android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_vertical_margin" android:layout_marginLeft="@dimen/activity_vertical_margin"
android:gravity="center"> android:gravity="center">
<com.yottacode.pictogram.tabletlibrary.gui.communicator.cropper.CropImageView <com.yottacode.pictogram.tabletlibrary.gui.communicator.cropper.CropImageView
android:id="@+id/CropImageView" android:id="@+id/CropImageView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:scaleType="centerInside" android:scaleType="centerInside"
android:layout_gravity="center" android:layout_gravity="center"
android:cropToPadding="false" android:cropToPadding="false"
/> />
</LinearLayout> </LinearLayout>
...@@ -54,16 +54,16 @@ ...@@ -54,16 +54,16 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@android:color/darker_gray" android:background="@android:color/darker_gray"
android:layout_marginRight="@dimen/activity_vertical_margin" /> android:layout_marginRight="@dimen/activity_vertical_margin" />
<FrameLayout <FrameLayout
android:orientation="vertical" android:orientation="vertical"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:id="@+id/legend_menu" android:id="@+id/legend_menu"
android:layout_gravity="right" android:layout_gravity="right"
android:layout_marginRight="@dimen/activity_vertical_margin" android:layout_marginRight="@dimen/activity_vertical_margin"
android:weightSum="1" android:weightSum="1"
android:layout_marginTop="@dimen/activity_vertical_margin" android:layout_marginTop="@dimen/activity_vertical_margin"
android:gravity="center_vertical|center"> android:gravity="center_vertical|center">
...@@ -75,49 +75,49 @@ ...@@ -75,49 +75,49 @@
android:layout_marginBottom="40dp"> android:layout_marginBottom="40dp">
<TextView <TextView
android:textColor= "@color/gray" android:textColor= "@color/gray"
android:textSize="20sp" android:textSize="20sp"
android:text="@string/legendText" android:text="@string/legendText"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/textLegend" android:id="@+id/textLegend"
android:layout_gravity="center" /> android:layout_gravity="center" />
<EditText <EditText
android:textSize="20sp" android:textSize="20sp"
android:imeOptions="actionDone" android:imeOptions="actionDone"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="10" android:ems="10"
android:id="@+id/edtLegend" android:id="@+id/edtLegend"
android:textColor="@color/black" android:textColor="@color/black"
android:layout_below="@+id/textLegend" android:layout_below="@+id/textLegend"
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center" android:gravity="center"
android:textColorLink="?android:attr/colorAccent" android:textColorLink="?android:attr/colorAccent"
android:maxLines="1" android:maxLines="1"
android:textCursorDrawable="@null" android:textCursorDrawable="@null"
/> />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:gravity="bottom|center_horizontal" android:gravity="bottom|center_horizontal"
android:layout_marginBottom="40dp"> android:layout_marginBottom="40dp">
<Button <Button
android:id="@+id/okButton" android:id="@+id/okButton"
android:layout_width="120dp" android:layout_width="120dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
android:textSize="18sp" android:textSize="18sp"
android:textAlignment="center" android:textAlignment="center"
android:text="@string/accept" android:text="@string/accept"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:capitalize="sentences" /> android:capitalize="sentences" />
<Button <Button
...@@ -134,9 +134,8 @@ ...@@ -134,9 +134,8 @@
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
...@@ -49,3 +49,8 @@ UNLOCK TABLES; ...@@ -49,3 +49,8 @@ UNLOCK TABLES;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2017-01-17 9:48:07 -- Dump completed on 2017-01-17 9:48:07
--
-- Creacion y volcado de datos para la tabla `pictocattree`
--
source /vagrant/roles/database/files/pictocat_tree_populate.sql
DROP TABLE IF EXISTS `pictocattree`;
CREATE TABLE pictocattree(
id_cat INT,
id_ancestor INT,
CONSTRAINT pk_primary_key PRIMARY KEY (id_cat, id_ancestor),
INDEX (id_ancestor)
);
DELIMITER $$
DROP PROCEDURE IF EXISTS picto_cat_tree $$
CREATE PROCEDURE picto_cat_tree()
BEGIN
DECLARE done, populated INT DEFAULT FALSE;
DECLARE _id, _id_supercat, x, _id_cat, _id_ancestor INT;
DECLARE pictocat CURSOR FOR SELECT id,id_supercat FROM pictodb.pictocat;
DECLARE pictocattree CURSOR FOR SELECT id_cat, id_ancestor FROM pictodb.pictocattree where id_cat = x;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN pictocat;
DELETE FROM pictocattree;
read_loop: LOOP
FETCH pictocat INTO _id, _id_supercat;
IF done THEN
LEAVE read_loop;
END IF;
INSERT INTO pictocattree (id_cat,id_ancestor) VALUES (_id, _id_supercat);
IF _id_supercat != 0 THEN
SET populated = 0;
populate_loop: LOOP
SET x = _id_supercat;
OPEN pictocattree;
FETCH pictocattree INTO _id_cat, _id_ancestor;
INSERT INTO pictocattree (id_cat, id_ancestor) VALUES (_id, _id_ancestor);
IF _id_ancestor = 0 THEN
LEAVE populate_loop;
END IF;
END LOOP;
CLOSE pictocattree;
END IF;
END LOOP;
CLOSE pictocat;
END $$
DELIMITER ;
CALL picto_cat_tree();
...@@ -24,6 +24,14 @@ ...@@ -24,6 +24,14 @@
state: import state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/symbolstix.sql" target: "{{ server_path }}/{{ database_files_relative_path }}/symbolstix.sql"
- name: Imports symbolstix categories
mysql_db:
login_user: "{{ database_user }}"
login_password: "{{ database_user_passwd }}"
name: "{{ database_name }}"
state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/pictocat.sql"
- name: Imports application essential data - name: Imports application essential data
mysql_db: mysql_db:
login_user: "{{ database_user }}" login_user: "{{ database_user }}"
......
...@@ -13,6 +13,9 @@ Changes to be performed manually in servers to upgrade ...@@ -13,6 +13,9 @@ Changes to be performed manually in servers to upgrade
## Database ## Database
- load pictocat_tree_populate.sql
`source /vagrant/roles/database/files/pictocat_tree_populate.sql;`
(already done in dev) (already done in dev)
- reload trigers-enrolments-integrity-constraints.sql - reload trigers-enrolments-integrity-constraints.sql
......
...@@ -148,18 +148,18 @@ module.exports = { ...@@ -148,18 +148,18 @@ module.exports = {
var fs = require('fs'); var fs = require('fs');
// return empty for category 0 (that represents category pictos and all custom pictos) // return empty for category 0 (that represents category pictos and all custom pictos)
if (req.params.id_cat == 0) // if (req.params.id_cat == 0)
return res.ok(l); // return res.ok(l);
Supervisor.findOne({ id: req.params.id }).then(function (supervisor) { Supervisor.findOne({ id: req.params.id }).then(function (supervisor) {
if (supervisor) { if (supervisor) {
PictoCat PictoCatTree
.find({select: ['id'], id_supercat: req.params.id_cat }) .find({select: ['id_cat'], id_ancestor: req.params.id_cat })
.then(function (categories) { .then(function (categories) {
var filtered = [req.params.id_cat]; var filtered = [req.params.id_cat]; // Category itself
for(var i =0; i<categories.length;i++){ for(var i =0; i<categories.length;i++){ //All subcategories
filtered.push(categories[i].id); filtered.push(categories[i].id_cat);
} }
Picto.find({ category: filtered }) Picto.find({ category: filtered })
.paginate({ page: req.params.page, limit: req.params.limit}) .paginate({ page: req.params.page, limit: req.params.limit})
...@@ -193,67 +193,11 @@ module.exports = { ...@@ -193,67 +193,11 @@ module.exports = {
.catch(function (err) { .catch(function (err) {
throw err; throw err;
}); });
//get all categories under id_cat
// var promise = new Promise(function(resolve, reject){
// var cats = [];
// var catsFiltered = [];
// cats = getCategories(req.params.id_cat);
// while(cats.length > 1){
// var cat = cats.pop().id;
// catsFiltered.push(cat);
// cats = cats.concat(getCategories(cat));
// }
// console.log(catsFiltered);
// resolve(catsFiltered);
// });
//promise.then(function(catsFiltered){
// Picto.find({ category: catsFiltered })
// .paginate({ page: req.params.page, limit: req.params.limit})
// .populate('expressions', { lang: supervisor.lang })
// .then(function (pictos) {
// async.eachSeries(pictos, function(picto, next_cb) {
//
// // check picto has expressions associated in student language
// if (picto.expressions.length == 0 || picto.expressions[0].text.length == 0)
// return next_cb();
//
// // check picto image is available
// picto.imageFileExists((found) => {
// if (found) {
// l.push(picto);
// next_cb();
// }
// else
// next_cb();
// });
// },
// function (err) { // loop has end
// if (err) throw err;
// sails.log.debug(pictos.length + " pictos sent for category " + req.params.id_cat + " in language " + supervisor.lang);
// return res.ok(l);
// }); // end async.eachSeries
// })
// .catch(() => res.badRequest());
//});
} else { } else {
return res.badRequest(); return res.badRequest();
} }
}) })
.catch(() => res.serverError()); .catch(() => res.serverError());
// function getCategories(id_cat){
// PictoCat
// .find({select: ['id'], id_supercat: id_cat })
// .then(function (categories) {
// console.log(categories);
// return categories;
// })
// .catch(function (err) {
// throw err;
// });
// }
}, },
/** /**
...@@ -287,12 +231,12 @@ module.exports = { ...@@ -287,12 +231,12 @@ module.exports = {
if (req.params.id_cat == 0){ //Search in all categories if (req.params.id_cat == 0){ //Search in all categories
getPictos(0, supervisor.lang, supervisor.id); getPictos(0, supervisor.lang, supervisor.id);
}else{//Get selected category and subcategories }else{//Get selected category and subcategories
PictoCat PictoCatTree
.find({select: ['id'], id_supercat: req.params.id_cat }) .find({select: ['id_cat'], id_ancestor: req.params.id_cat })
.then(function (categories) { .then(function (categories) {
var filtered = [Number(req.params.id_cat)]; //Get returned ID var filtered = [req.params.id_cat]; //Category itself
for(var i =0; i<categories.length;i++){ for(var i =0; i<categories.length;i++){ //All subcategories
filtered.push(categories[i].id); filtered.push(categories[i].id_cat);
} }
getPictos(filtered, supervisor.lang, supervisor.id); getPictos(filtered, supervisor.lang, supervisor.id);
}) })
......
...@@ -827,22 +827,35 @@ module.exports = { ...@@ -827,22 +827,35 @@ module.exports = {
/** /**
* Add an existing picto to the student's collection * Add an existing picto to the student's collection
* @param {request} req (with studentId and pictoId as url parameter) * @param {request} req (with id_stu and id_picto as url parameters)
* { * {
* id_stu,
* id_picto,
* attributes: { @see StuPicto.getValidAttributes() } * attributes: { @see StuPicto.getValidAttributes() }
* } * }
* @param {response} res *
* { * @param {response} res {
* id: stuPictoId (association betweet student and picto) * id: <stu_picto ID>,
* student: studentId (speficied as url parameter) * student: <student ID>,
* picto: { @see Picto model} * attributes: {
* attributes: { @see StuPicto.getValidAttributes() } * id_cat: categoryId or null,
* coord_x: 1 .. 5 or null,
* coord_y: 1 .. 10 or null,
* free_category_coord_x: 0 .. 4 or null,
* free_category_coord_y: 0 .. 9 or null,
* status: '[invisible]/enabled/disabled',
* highlight: true/[false],
* legend: true/[false],
* legend_size: '[small]/large',
* expression: 'custom expression',
* color: any valid HEX color or [null]
* }
* } * }
*/ */
add_picto: function (req, res) { add_picto: function (req, res) {
var params = req.allParams(); var params = req.allParams();
StuPicto.find({id_pic: params.id_picto}) StuPicto.find({id_pic: params.id_picto, id_stu: params.id_stu})
.then((entries) => { .then((entries) => {
if (entries && entries.length > 0) { if (entries && entries.length > 0) {
var err = new Error("Picto already in student's vocabulary"); var err = new Error("Picto already in student's vocabulary");
......
/**
* pictocat.js
*
* @description :: TODO: Write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
tableName : 'pictocattree',
migrate : 'safe',
schema : true,
autoPK : false,
autoCreatedAt : false,
autoUpdatedAt : false,
attributes: {
id_cat: {
type: "integer",
primaryKey: true,
unique: true
},
id_ancestor: {
type: "integer",
primaryKey: true,
required: false
}
}
};
...@@ -39,28 +39,6 @@ dashboardControllers.controller('AddPictoCtrl', function ( ...@@ -39,28 +39,6 @@ dashboardControllers.controller('AddPictoCtrl', function (
exp: 'Inicio', exp: 'Inicio',
glyphicon: 'glyphicon glyphicon-home' glyphicon: 'glyphicon glyphicon-home'
}); });
// Request of general pictos categories (symbolstx)
$http.get(config.backend + '/sup/' + supervisor.id + '/pic_categories/0')
.success(function (data) {
$scope.symbolstxCats = data;
})
.error(function () {
$translate('error_loading_pictos').then(function (translation) {
ngToast.danger({ content: translation });
});
});
// Request page 1 pictos (symbolstx)
$http.get(config.backend + '/sup/' + supervisor.id + '/pic_fromSymbolStx/page/1/limit/'+$scope.limit)
.success(function (data) {
$scope.pictos = data;
})
.error(function () {
$translate('error_loading_pictos').then(function (translation) {
ngToast.danger({ content: translation });
});
});
} }
// //
...@@ -80,8 +58,9 @@ dashboardControllers.controller('AddPictoCtrl', function ( ...@@ -80,8 +58,9 @@ dashboardControllers.controller('AddPictoCtrl', function (
} }
$http.get(request) $http.get(request)
.success(function (data) { .success(function (data) {
if (data) if (data && $scope.source == 'symbolstx'){
$scope.pictos = data; $scope.pictos = data;
}
$scope.loadingCatPictos = false; $scope.loadingCatPictos = false;
setTimeout(function () { $scope.$apply(); }); setTimeout(function () { $scope.$apply(); });
}) })
...@@ -122,9 +101,12 @@ dashboardControllers.controller('AddPictoCtrl', function ( ...@@ -122,9 +101,12 @@ dashboardControllers.controller('AddPictoCtrl', function (
$http.get(config.backend+'/sup/'+ supervisor.id +'/pic_categories/' + categoryId) $http.get(config.backend+'/sup/'+ supervisor.id +'/pic_categories/' + categoryId)
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
// Add to list // Add to list
if (data) if (data && $scope.source == 'symbolstx'){
$scope.symbolstxCats = data; $scope.symbolstxCats = data;
else $scope.symbolstxCats = []; }
else{
$scope.symbolstxCats = [];
}
}) })
.error(function(data, status, headers, config) { .error(function(data, status, headers, config) {
}); });
...@@ -173,7 +155,7 @@ dashboardControllers.controller('AddPictoCtrl', function ( ...@@ -173,7 +155,7 @@ dashboardControllers.controller('AddPictoCtrl', function (
}; };
$scope.addOwnPicto = function () { $scope.addOwnPicto = function () {
console.log($scope.picFile);
$scope.progress = 0; $scope.progress = 0;
var modalInstance = $modal.open({ var modalInstance = $modal.open({
animation: true, animation: true,
...@@ -186,7 +168,7 @@ dashboardControllers.controller('AddPictoCtrl', function ( ...@@ -186,7 +168,7 @@ dashboardControllers.controller('AddPictoCtrl', function (
progress: () => {return $scope.progress;} progress: () => {return $scope.progress;}
} }
}); });
modalInstance.result.then(function () {}); modalInstance.result.then(function () {$scope.picFile=null;});
}; };
/** /**
...@@ -212,7 +194,7 @@ dashboardControllers.controller('AddPictoCtrl', function ( ...@@ -212,7 +194,7 @@ dashboardControllers.controller('AddPictoCtrl', function (
picto.expressions = []; picto.expressions = [];
$scope.open_exp(picto, () => { $scope.open_exp(picto, () => {
$scope.pictos.push(picto); $scope.pictos.push(picto);
load_own_pictos(); $scope.load_own_pictos();
cb(); cb();
}); });
}); });
...@@ -295,8 +277,8 @@ dashboardControllers.controller('AddPictoCtrl', function ( ...@@ -295,8 +277,8 @@ dashboardControllers.controller('AddPictoCtrl', function (
//Triggered when scrolling to bottom //Triggered when scrolling to bottom
$scope.scroll = function(){ $scope.scroll = function(){
if ($scope.onlyOwn) if ($scope.onlyOwn || $scope.source == 'ownpictos')
return; return; //When ownpictos is active, load whole own pictos at once
$scope.loadingCatPictos = true; $scope.loadingCatPictos = true;
$scope.page += 1; $scope.page += 1;
...@@ -379,7 +361,13 @@ dashboardControllers.controller('AddPictoCtrl', function ( ...@@ -379,7 +361,13 @@ dashboardControllers.controller('AddPictoCtrl', function (
} }
}; };
if (onlyOwn) //Initial load category and pictos
if (onlyOwn){
$scope.load_own_pictos(); $scope.load_own_pictos();
}
else {
$scope.load_category(0);
$scope.load_pictos(0);
}
}); });
...@@ -369,6 +369,9 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -369,6 +369,9 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
// Returned data from the modal window // Returned data from the modal window
modalInstance.result.then(function (pictoId) { modalInstance.result.then(function (pictoId) {
if(!pictoId)
return;
// Send the picto to the server // Send the picto to the server
$http.post(config.backend + '/stu/' + $scope.studentData.id + '/picto/' + pictoId, { $http.post(config.backend + '/stu/' + $scope.studentData.id + '/picto/' + pictoId, {
attributes: { attributes: {
......
...@@ -27,7 +27,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -27,7 +27,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.paused = false; $scope.paused = false;
// Read the last working session to show the last tries when session tab is opened // Array with working sessions for selected instruction
$scope.wsessions = []; $scope.wsessions = [];
// Array with student methods (with instructions) // Array with student methods (with instructions)
...@@ -63,9 +63,6 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -63,9 +63,6 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
// Add to list // Add to list
$scope.wsessions = data; $scope.wsessions = data;
$scope.currentPage = 1;
$scope.numPerPage = 5;
$scope.totalPages = Math.ceil($scope.wsessions.length / $scope.numPerPage);
$scope.ws_recover = $scope.wsessions[0]!=null && $scope.wsessions[0].end==null; $scope.ws_recover = $scope.wsessions[0]!=null && $scope.wsessions[0].end==null;
}) })
.error(function(data, status, headers, config) { .error(function(data, status, headers, config) {
...@@ -94,24 +91,10 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -94,24 +91,10 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
// Add to list // Add to list
$scope.wsessions = data; $scope.wsessions = data;
// Refresh navigation vars
$scope.currentPage = 1;
$scope.numPerPage = 5;
$scope.totalPages = Math.ceil($scope.wsessions.length / $scope.numPerPage);
}) })
.error(function(data, status, headers, config) {}); .error(function(data, status, headers, config) {});
}; };
// Tries pagination - previous tries
$scope.before = function(){
if($scope.currentPage > 1) $scope.currentPage--;
};
// Tries pagination - next tries
$scope.after = function(){
var total_pages = Math.ceil($scope.wsessions.length / $scope.numPerPage);
if($scope.currentPage < total_pages) $scope.currentPage++;
};
// //
// Evaluate a try (result update request) // Evaluate a try (result update request)
...@@ -366,8 +349,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -366,8 +349,8 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
*/ */
$scope.is_currentOpenTry = function(t) { $scope.is_currentOpenTry = function(t) {
if (t.end==null && $scope.ws.id==t.workingSession) { if (t.end == null && $scope.ws.id == t.workingSession) {
$scope.actual_try.id=t.id; $scope.actual_try.id = t.id;
return true; return true;
} }
return false; return false;
......
<div> <div>
<div class="modal-header">
<div class="modal-header">
<button type="button" class="close" ng-click="close()"> <button type="button" class="close" ng-click="close()">
<span aria-hidden="true">&times;</span><span class="sr-only" translate>close</span> <span aria-hidden="true">&times;</span><span class="sr-only" translate>close</span>
</button> </button>
<h4 class="modal-title" id="myModalLabel" translate ng-show="!onlyOwn">add_picto</h4> <h4 class="modal-title" id="myModalLabel" translate ng-show="!onlyOwn">add_picto</h4>
<h4 class="modal-title" id="myModalLabel" translate ng-show="onlyOwn">own_pictos</h4> <h4 class="modal-title" id="myModalLabel" translate ng-show="onlyOwn">own_pictos</h4>
...@@ -18,10 +19,12 @@ ...@@ -18,10 +19,12 @@
<span class="glyphicon glyphicon-picture"></span> {{ 'own_pictos' | translate }} <span class="glyphicon glyphicon-picture"></span> {{ 'own_pictos' | translate }}
</button> </button>
</div> </div>
</div>
</div><!-- /modal-header -->
<div class="modal-body"> <div class="modal-body">
<!-- Bread and categories -->
<div id="bread_and_categories" ng-show="source == 'symbolstx' && !onlyOwn" class="panel panel-default"> <div id="bread_and_categories" ng-show="source == 'symbolstx' && !onlyOwn" class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<div class="pull-left" ng-repeat="b in breadcrumbs"> <div class="pull-left" ng-repeat="b in breadcrumbs">
...@@ -44,56 +47,62 @@ ...@@ -44,56 +47,62 @@
<alert ng-show="alert.show" ng-model="alert" type="{{alert.type}}" close="closeAlert()">{{alert.msg | translate}}</alert> <alert ng-show="alert.show" ng-model="alert" type="{{alert.type}}" close="closeAlert()">{{alert.msg | translate}}</alert>
</div> </div>
<div id="collections" class="col-md-12 category-collection" <!-- Collections row -->
ng-class="{ 'category-collection-loading': loadingCatPictos }" <div class="row">
data-loading="{{ 'loading_pictos' | translate }}">
<form ng-submit="search()" ng-show="!onlyOwn"> <!-- Collections -->
<div class="input-group" id="search_pictos_box"> <div id="collections" class="col-md-12 category-collection"
<input type="text" class="form-control" placeholder="{{ 'filter' | translate }}" ng-class="{ 'category-collection-loading': loadingCatPictos }"
id="srch_term_picto" name="srch_term_picto" ng-model="srch_term_picto"> data-loading="{{ 'loading_pictos' | translate }}">
<span class="input-group-btn">
<button type="submit" class="btn btn-primary"> <!-- Filter form -->
<i class="fa fa-search" aria-hidden="true"></i> {{ 'search' | translate }} <form ng-submit="search()" ng-show="!onlyOwn">
</button> <div class="input-group" id="search_pictos_box">
</span> <input type="text" class="form-control" placeholder="{{ 'filter' | translate }}"
</div> id="srch_term_picto" name="srch_term_picto" ng-model="srch_term_picto">
</form> <span class="input-group-btn">
<div ng-show="source == 'ownpictos'" class="input-group"> <button type="submit" class="btn btn-default">
<button class="btn btn-success" ngf-select ng-model="picFile" accept="image/*" ngf-change="addOwnPicto()"> <i class="fa fa-search" aria-hidden="true"></i>
<span class="glyphicon glyphicon-folder-open"></span> {{ 'new_img' | translate }} </button>
</button> </span>
</div>
<!-- Galería de pictos -->
<div id="clearfix-infiniteScroll-parent" infinite-scroll="scroll()"
infinite-scroll-container="'#collections'">
<div
class="picto_peq pull-left"
ng-repeat="p in pictos" >
<img ng-src="{{p.uri}}" popover="{{p.expressions[0].text}}" popover-trigger="mouseenter" />
<div class="picto_options">
<!-- Options to remove picto (Only for own pictos) -->
<a ng-click="remove_own_picto(p.id)" class="picto_remove" title="{{ 'delete' | translate}}" ng-show="source == 'ownpictos'">
<span class="color_red glyphicon glyphicon-remove-circle" aria-hidden="true"></span>
</a>
<a ng-show="!onlyOwn"
ng-click="close(p.id)"
class="picto_add"
title="{{ 'add_picto' | translate}}">
<span class="color_green glyphicon glyphicon-plus-sign" aria-hidden="true"></span>
</a>
</div> </div>
</form>
<!-- Add new image -->
<div ng-show="source == 'ownpictos'" class="input-group">
<button class="btn btn-success" ngf-select ng-model="picFile" accept="image/*" ngf-change="addOwnPicto()">
<span class="glyphicon glyphicon-folder-open"></span> {{ 'new_img' | translate }}
</button>
</div> </div>
<div class="clearfix"></div> <!-- Picto galery -->
<div id="clearfix-infiniteScroll-parent" infinite-scroll="scroll()" infinite-scroll-container="'#collections'">
</div><!-- /collections --> <div class="picto_peq pull-left" ng-repeat="p in pictos" >
<img ng-src="{{p.uri}}" popover="{{p.expressions[0].text}}" popover-trigger="mouseenter" />
<!-- Options to remove picto (Only for own pictos) -->
<div class="picto_options">
<a ng-click="remove_own_picto(p.id)" class="picto_remove" title="{{ 'delete' | translate}}" ng-show="source == 'ownpictos'">
<span class="color_red glyphicon glyphicon-remove-circle" aria-hidden="true"></span>
</a>
<a ng-show="!onlyOwn"
ng-click="close(p.id)"
class="picto_add"
title="{{ 'add_picto' | translate}}">
<span class="color_green glyphicon glyphicon-plus-sign" aria-hidden="true"></span>
</a>
</div><!-- /picto-options -->
</div><!-- /each picto -->
</div><!-- /row --> <div class="clearfix"></div>
</div> <!-- /modal-body --> </div><!-- /picto galery -->
</div><!-- /collections -->
</div><!-- /collections row -->
</div><!-- /modal-body -->
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-primary" ng-click="cancel()">{{ 'close' | translate }}</button> <button class="btn btn-primary" ng-click="cancel()">{{ 'close' | translate }}</button>
</div> </div><!-- /modal-footer -->
</div> </div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment