throw new Error("Not implemented");
}
get last_done() {
- return this.datesDone.slice(0,1);
+ let res = this.datesDone.slice(0,1);
+ if(res.length==0) {
+ return "";
+ } else {
+ return res[0];
+ }
}
remove(date) {
for(let i=0;i<this.datesDone.length;i++) {
import Main from './main.component.js';
import {constants} from '../../constants.js';
-const {CHANGE_VIEW} = constants;
+const {CHANGE_VIEW,SORT_VIEW} = constants;
const mapStateToParentProps = (state) => {
const {workouts} = state;
workouts:ownProps.workouts,
view
});
+ dispatch({
+ type:SORT_VIEW,
+ key:(view=="manage")?"last_done":"date",
+ shift:false
+ });
}
};
};
"description",
"done"
].map((field) => {
- let val;
if(field=="done") {
return createElement("td",{key:"cell-"+field},
createElement("input",{type:"button",value:"Completed",onClick:this.completeWorkout})
);
- } else if(data[field] === void(0)) {
- return createElement("td",{key:"cell-attr-"+field,onClick:this.toggleAttribute.bind(this,field)},
- (data.attributes[field])?"Yes":"No"
- );
} else if(field=="name") {
return createElement("td",{key:"cell-"+field},
createElement("input",{defaultValue:data[field],onBlur:this.changeName})
return createElement("td",{key:"cell-"+field},
createElement("textarea",{value:data[field],onChange:this.changeDescription})
);
+ } else if((field=="times_done")||(field=="last_done")) {
+ return createElement("td",{key:"cell-"+field},data[field]);
} else {
- return createElement("td",{key:"cell-"+field},val);
+ return createElement("td",{key:"cell-attr-"+field,onClick:this.toggleAttribute.bind(this,field)},
+ (data[field])?"Yes":"No"
+ );
}
});
return createElement("tr",null,
].map((x) => {
return createElement("th",{key:"head-"+x,onClick:this.handleSort.bind(this,x)},x);
});
- const rows = Object.keys(workouts).map((i) => {
+ const rows = workouts.map((i) => {
return createElement(manageRow,{
- key:"row-"+i,
- data:workouts[i],
- complete:() => completeWorkout(i),
- description:(val) => changeDescription(i,val),
- name:(val) => changeName(i,val),
- toggle:(attr) => toggleAttribute(i,attr)
+ key:"row-"+i.name,
+ data:i,
+ complete:() => completeWorkout(i.name),
+ description:(val) => changeDescription(i.name,val),
+ name:(val) => changeName(i.name,val),
+ toggle:(attr) => toggleAttribute(i.name,attr)
});
});
return createElement("div",{className:style.container},
:local(.container) {
-
+ width:100%;
+ height:100%;
+ overflow:scroll;
}
:local(.container) > input {
const {ADD_WORKOUT,CHANGE_ATTRIBUTE,CHANGE_WORKOUT_DESCRIPTION,CHANGE_WORKOUT_NAME,NEW_WORKOUT,SORT_VIEW} = constants;
const mapStateToProps = (state) => {
- const {workouts} = state;
return {
- workouts
+ workouts:state.view.data
};
};
import recentRow from '../recent.row/recent.row.js';
export default class Recent extends React.Component {
+ constructor(props) {
+ super(props);
+ this.handleSort = this.handleSort.bind(this);
+ }
+ handleSort(key,event) {
+ this.props.handleSort(key,event.shiftKey);
+ }
render() {
- const {data,handleDateChange} = this.props;
- const headers = ["workout name","date"].map((x) => {
- return createElement("th",{key:"head-"+x},x);
+ const {data,handleDateChange,handleSort} = this.props;
+ const headers = ["name","date"].map((x) => {
+ return createElement("th",{key:"head-"+x,onClick:this.handleSort.bind(this,x)},x);
});
const rows = data.map((i) => {
return createElement(recentRow,{
:local(.container) {
-
+ width:100%;
+ height:100%;
+ overflow:scroll;
}
:local(.table) {
import Recent from './recent.component.js';
import {constants} from '../../constants.js';
-const {CHANGE_WORKOUT_DATE} = constants;
+const {CHANGE_WORKOUT_DATE,SORT_VIEW} = constants;
const mapStateToProps = (state) => {
return {
- data:state.view.data
+ data:state.view.data.slice(0,100)
};
}
old,
new:date
});
+ },
+ handleSort:(key) => {
+ dispatch({
+ type:SORT_VIEW,
+ key,
+ shift:false
+ });
}
};
}
const daysAgo = {...defaultDaysAgo};
const now = new Date();
for(let i in workouts) {
- const last = workouts[i].last_done[0];
- if(last === void(0)) {
+ const last = workouts[i].last_done;
+ if(last === "") {
continue;
}
let lastDate = new Date(last);
}
switch(action.view) {
case "manage":
- console.log('manage');
const newStateManageView = {
...state,
view:"manage"
};
newStateManageView.data = [];
- for(let i=0;i<action.workouts.length;i++) {
- newStateManageView.data.push({
- attributes:actions.workouts[i].attributes,
- name:actions.workouts[i].name,
- last_done:actions.workouts[i].last_done,
- description:actions.workouts[i].description
- });
+ for(let i in action.workouts) {
+ let toPush = {};
+ for(let j in DEFAULT_ATTRIBUTES) {
+ toPush[j] = action.workouts[i].attributes[j];
+ }
+ toPush.name = action.workouts[i].name;
+ toPush.times_done = action.workouts[i].times_done;
+ toPush.last_done = action.workouts[i].last_done;
+ toPush.description = action.workouts[i].description;
+ newStateManageView.data.push(toPush);
}
newStateManageView.daysAgo = generateDaysAgo(action.workouts);
- console.log(JSON.stringify(newStateManageView.data));
return newStateManageView;
case "recent":
- console.log('recent');
const newStateRecentView = {
...state,
view:"recent"
}
}
newStateRecentView.daysAgo = generateDaysAgo(action.workouts);
- console.log(JSON.stringify(newStateRecentView.data));
return newStateRecentView;
default:
return state;
}
case SORT_VIEW:
+ console.log(SORT_VIEW);
if(action.key === void(0)) {
return state;
}
}
newStateAfterSort.sortKey = newSortKey;
newStateAfterSort.sortOrder = newSortOrder;
- console.log(state.data);
- console.log(newStateAfterSort.data);
newStateAfterSort.data.sort((a,b) => {
for(let i=0;i<newSortKey.length;i++) {
- console.log(a[newSortKey[i]],b[newSortKey[i]]);
if(a[newSortKey[i]]<b[newSortKey[i]]) {
return (newSortOrder[i]=="asc")?-1:1;
} else if(a[newSortKey[i]]>b[newSortKey[i]]) {