kopia lustrzana https://github.com/OpenDroneMap/WebODM
Added stateful URL parameters for opening project tasks's and individual task details
rodzic
23af449853
commit
0b83c8ff4c
|
@ -39,7 +39,7 @@ class Dashboard extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
const projectList = ({ location, history }) => {
|
const projectList = ({ location, history }) => {
|
||||||
let q = Utils.queryParams(location),
|
let q = Utils.queryParams(location),
|
||||||
page = parseInt(q.page);
|
page = parseInt(q.page !== undefined ? q.page : 1);
|
||||||
|
|
||||||
return <ProjectList
|
return <ProjectList
|
||||||
source={`/api/projects/?ordering=-created_at&page=${page}`}
|
source={`/api/projects/?ordering=-created_at&page=${page}`}
|
||||||
|
|
|
@ -1,16 +1,54 @@
|
||||||
import Utils from './Utils';
|
import Utils from './Utils';
|
||||||
|
|
||||||
|
const SEP = ",";
|
||||||
|
|
||||||
class HistoryNav{
|
class HistoryNav{
|
||||||
constructor(history){
|
constructor(history){
|
||||||
this.history = history;
|
this.history = history;
|
||||||
}
|
}
|
||||||
|
|
||||||
changeQueryString(param, value){
|
changeQS(param, value){
|
||||||
this.history.replace(
|
this.history.replace(
|
||||||
this.history.location.pathname +
|
this.history.location.pathname +
|
||||||
Utils.replaceSearchQueryParam(this.history.location, param, value) +
|
Utils.replaceSearchQueryParam(this.history.location, param, value) +
|
||||||
this.history.location.hash);
|
this.history.location.hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isValueInQSList(param, value){
|
||||||
|
let q = Utils.queryParams(this.history.location);
|
||||||
|
if (q[param]){
|
||||||
|
return q[param].split(SEP).find(v => v == value);
|
||||||
|
}else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
addToQSList(param, value){
|
||||||
|
let q = Utils.queryParams(this.history.location);
|
||||||
|
if (q[param]){
|
||||||
|
if (!this.isValueInQSList(param, value)){
|
||||||
|
this.changeQS(param, q[param] + SEP + value);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
this.changeQS(param, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removeFromQSList(param, value){
|
||||||
|
let q = Utils.queryParams(this.history.location);
|
||||||
|
if (q[param]){
|
||||||
|
let parts = q[param].split(SEP);
|
||||||
|
this.changeQS(param,
|
||||||
|
parts.filter(p => p != value).join(SEP)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleQSListItem(param, value, add){
|
||||||
|
if (add){
|
||||||
|
this.addToQSList(param, value);
|
||||||
|
}else{
|
||||||
|
this.removeFromQSList(param, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default HistoryNav;
|
export default HistoryNav;
|
||||||
|
|
|
@ -39,7 +39,7 @@ export default {
|
||||||
toSearchQuery: function(params){
|
toSearchQuery: function(params){
|
||||||
let parts = [];
|
let parts = [];
|
||||||
for (let k in params){
|
for (let k in params){
|
||||||
parts.push(encodeURIComponent(k) + "=" + encodeURIComponent(params[k]));
|
parts.push(k + "=" + params[k]);
|
||||||
}
|
}
|
||||||
if (parts.length > 0) return "?" + parts.join("&");
|
if (parts.length > 0) return "?" + parts.join("&");
|
||||||
else return "";
|
else return "";
|
||||||
|
|
|
@ -51,7 +51,7 @@ class Paginated extends React.Component{
|
||||||
|
|
||||||
if (currentPage > pagesAfter) currentPage = pagesAfter;
|
if (currentPage > pagesAfter) currentPage = pagesAfter;
|
||||||
|
|
||||||
this.historyNav.changeQueryString('page', currentPage);
|
this.historyNav.changeQS('page', currentPage);
|
||||||
|
|
||||||
this.setPaginationState({
|
this.setPaginationState({
|
||||||
totalItems: this.state.pagination.totalItems + delta
|
totalItems: this.state.pagination.totalItems + delta
|
||||||
|
|
|
@ -89,7 +89,11 @@ class ProjectList extends Paginated {
|
||||||
<Paginator className="text-right" {...this.state.pagination} {...this.props}>
|
<Paginator className="text-right" {...this.state.pagination} {...this.props}>
|
||||||
<ul className={"list-group project-list " + (this.state.refreshing ? "refreshing" : "")}>
|
<ul className={"list-group project-list " + (this.state.refreshing ? "refreshing" : "")}>
|
||||||
{this.state.projects.map(p => (
|
{this.state.projects.map(p => (
|
||||||
<ProjectListItem key={p.id} data={p} onDelete={this.handleDelete} />
|
<ProjectListItem
|
||||||
|
key={p.id}
|
||||||
|
data={p}
|
||||||
|
onDelete={this.handleDelete}
|
||||||
|
history={this.props.history} />
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</Paginator>
|
</Paginator>
|
||||||
|
|
|
@ -8,14 +8,17 @@ import ErrorMessage from './ErrorMessage';
|
||||||
import EditProjectDialog from './EditProjectDialog';
|
import EditProjectDialog from './EditProjectDialog';
|
||||||
import Dropzone from '../vendor/dropzone';
|
import Dropzone from '../vendor/dropzone';
|
||||||
import csrf from '../django/csrf';
|
import csrf from '../django/csrf';
|
||||||
|
import HistoryNav from '../classes/HistoryNav';
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
|
|
||||||
class ProjectListItem extends React.Component {
|
class ProjectListItem extends React.Component {
|
||||||
constructor(props){
|
constructor(props){
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
|
this.historyNav = new HistoryNav(props.history);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
showTaskList: false,
|
showTaskList: this.historyNav.isValueInQSList("project_task_open", props.data.id),
|
||||||
updatingTask: false,
|
updatingTask: false,
|
||||||
upload: this.getDefaultUploadState(),
|
upload: this.getDefaultUploadState(),
|
||||||
error: "",
|
error: "",
|
||||||
|
@ -201,8 +204,12 @@ class ProjectListItem extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleTaskList(){
|
toggleTaskList(){
|
||||||
|
const showTaskList = !this.state.showTaskList;
|
||||||
|
|
||||||
|
this.historyNav.toggleQSListItem("project_task_open", this.state.data.id, showTaskList);
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
showTaskList: !this.state.showTaskList
|
showTaskList: showTaskList
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,6 +365,7 @@ class ProjectListItem extends React.Component {
|
||||||
ref={this.setRef("taskList")}
|
ref={this.setRef("taskList")}
|
||||||
source={`/api/projects/${data.id}/tasks/?ordering=-created_at`}
|
source={`/api/projects/${data.id}/tasks/?ordering=-created_at`}
|
||||||
onDelete={this.taskDeleted}
|
onDelete={this.taskDeleted}
|
||||||
|
history={this.props.history}
|
||||||
/> : ""}
|
/> : ""}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,8 +3,8 @@ import '../css/TaskList.scss';
|
||||||
import TaskListItem from './TaskListItem';
|
import TaskListItem from './TaskListItem';
|
||||||
|
|
||||||
class TaskList extends React.Component {
|
class TaskList extends React.Component {
|
||||||
constructor(){
|
constructor(props){
|
||||||
super();
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
tasks: [],
|
tasks: [],
|
||||||
|
@ -75,7 +75,12 @@ class TaskList extends React.Component {
|
||||||
{message}
|
{message}
|
||||||
|
|
||||||
{this.state.tasks.map(task => (
|
{this.state.tasks.map(task => (
|
||||||
<TaskListItem data={task} key={task.id} refreshInterval={3000} onDelete={this.deleteTask} />
|
<TaskListItem
|
||||||
|
data={task}
|
||||||
|
key={task.id}
|
||||||
|
refreshInterval={3000}
|
||||||
|
onDelete={this.deleteTask}
|
||||||
|
history={this.props.history} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,13 +6,16 @@ import pendingActions from '../classes/PendingActions';
|
||||||
import ErrorMessage from './ErrorMessage';
|
import ErrorMessage from './ErrorMessage';
|
||||||
import EditTaskDialog from './EditTaskDialog';
|
import EditTaskDialog from './EditTaskDialog';
|
||||||
import AssetDownloadButtons from './AssetDownloadButtons';
|
import AssetDownloadButtons from './AssetDownloadButtons';
|
||||||
|
import HistoryNav from '../classes/HistoryNav';
|
||||||
|
|
||||||
class TaskListItem extends React.Component {
|
class TaskListItem extends React.Component {
|
||||||
constructor(props){
|
constructor(props){
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
this.historyNav = new HistoryNav(props.history);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
expanded: false,
|
expanded: this.historyNav.isValueInQSList("project_task_expanded", props.data.id),
|
||||||
task: {},
|
task: {},
|
||||||
time: props.data.processing_time,
|
time: props.data.processing_time,
|
||||||
actionError: "",
|
actionError: "",
|
||||||
|
@ -111,8 +114,12 @@ class TaskListItem extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleExpanded(){
|
toggleExpanded(){
|
||||||
|
const expanded = !this.state.expanded;
|
||||||
|
|
||||||
|
this.historyNav.toggleQSListItem("project_task_expanded", this.props.data.id, expanded);
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
expanded: !this.state.expanded
|
expanded: expanded
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue