Show the most recently-created publication first when creating a new article.

master
Pacman Ghost 4 years ago
parent e96750a695
commit 5b9ea6636d
  1. 1
      asl_articles/publications.py
  2. 25
      web/src/ArticleSearchResult2.js
  3. 2
      web/src/constants.js

@ -59,6 +59,7 @@ def get_publication_vals( pub, add_type=False ):
"pub_image_id": pub.pub_id if pub.pub_image else None,
"pub_tags": decode_tags( pub.pub_tags ),
"publ_id": pub.publ_id,
"time_created": int( pub.time_created.timestamp() ) if pub.time_created else None,
}
if add_type:
vals[ "type" ] = "publication"

@ -1,6 +1,7 @@
import React from "react" ;
import Select from "react-select" ;
import CreatableSelect from "react-select/creatable" ;
import { NEW_ARTICLE_PUB_PRIORITY_CUTOFF } from "./constants.js" ;
import { PublicationSearchResult } from "./PublicationSearchResult.js" ;
import { gAppRef } from "./index.js" ;
import { ImageFileUploader } from "./FileUploader.js" ;
@ -13,7 +14,9 @@ export class ArticleSearchResult2
static _doEditArticle( vals, notify ) {
// initialize
let refs = {} ;
const isNew = Object.keys( vals ).length === 0 ;
// initialize the image
let imageFilename=null, imageData=null ;
@ -44,14 +47,29 @@ export class ArticleSearchResult2
// initialize the publications
let publications = [ { value: null, label: <i>(none)</i> } ] ;
let mostRecentPub = null ;
for ( let p of Object.entries(gAppRef.caches.publications) ) {
const pub_display_name = PublicationSearchResult.makeDisplayName( p[1] ) ;
publications.push( {
const pub = {
value: p[1].pub_id,
label: <span dangerouslySetInnerHTML={{__html: pub_display_name}} />
} ) ;
label: <span dangerouslySetInnerHTML={{__html: pub_display_name}} />,
} ;
publications.push( pub ) ;
if ( mostRecentPub === null || p[1].time_created > mostRecentPub[1] )
mostRecentPub = [ pub, p[1].time_created ] ;
}
sortSelectableOptions( publications ) ;
if ( isNew && mostRecentPub ) {
// NOTE: If the user is creating a new article, we check for the most recently-created publication
// and put that at the the top of list. This makes things easier in the most common use-case:
// the user has received a new magazine and is entering all the articles from it.
const now = new Date() / 1000 | 0 ;
const delta = now - mostRecentPub[1] ; // nb: we ignore server/client time zones
if ( delta <= NEW_ARTICLE_PUB_PRIORITY_CUTOFF ) {
publications = publications.filter( p => p !== mostRecentPub[0] ) ;
publications.splice( 1, 0, mostRecentPub[0] ) ;
}
}
let currPub = publications[0] ;
for ( let i=1; i < publications.length ; ++i ) {
if ( publications[i].value === vals.pub_id ) {
@ -183,7 +201,6 @@ export class ArticleSearchResult2
} ;
// show the form
const isNew = Object.keys( vals ).length === 0 ;
gAppRef.showModalForm( "article-form", isNew?"New article":"Edit article", "#d3edfc", content, buttons ) ;
}

@ -1 +1,3 @@
export let MAX_IMAGE_UPLOAD_SIZE = ( 1 * 1024*1024 ) ;
export let NEW_ARTICLE_PUB_PRIORITY_CUTOFF = ( 24 * 60 * 60 ) ;

Loading…
Cancel
Save