Mark as deprecated an recommend vue instead

This commit is contained in:
Tobias Johansson 2019-03-29 14:42:33 +01:00
parent 1d476d03d7
commit 119900337d
8 changed files with 59 additions and 10 deletions

View File

@ -0,0 +1,2 @@
This module is used to render nodes/users dynamically. It was written before we introduced vue.js into the project.
Current best practice is to use vue for this type of work.

View File

@ -2,25 +2,50 @@ import { ComponentCreatorInterface } from './ComponentCreatorInterface'
const REGISTERED_CREATORS = []
/**
* Create a jQuery renderable element from a mongo document using registered creators.
* @deprecated use vue instead
*/
export class Component extends ComponentCreatorInterface {
/**
*
* @param {Object} doc
* @returns {$element}
*/
static create$listItem(doc) {
let creator = Component.getCreator(doc);
return creator.create$listItem(doc);
}
/**
* @param {Object} doc
* @returns {$element}
*/
static create$item(doc) {
let creator = Component.getCreator(doc);
return creator.create$item(doc);
}
/**
* @param {Object} candidate
* @returns {Boolean}
*/
static canCreate(candidate) {
return !!Component.getCreator(candidate);
}
/**
* Register component creator to handle a node type
* @param {ComponentCreatorInterface} creator
*/
static regiseterCreator(creator) {
REGISTERED_CREATORS.push(creator);
}
/**
* @param {Object} doc
* @returns {ComponentCreatorInterface}
*/
static getCreator(doc) {
if (doc) {
for (let candidate of REGISTERED_CREATORS) {
@ -31,4 +56,4 @@ export class Component extends ComponentCreatorInterface {
}
throw 'Can not create component using: ' + JSON.stringify(doc);
}
}
}

View File

@ -1,6 +1,10 @@
/**
* @deprecated use vue instead
*/
export class ComponentCreatorInterface {
/**
* @param {JSON} doc
* Create a $element to render document in a list
* @param {Object} doc
* @returns {$element}
*/
static create$listItem(doc) {
@ -8,8 +12,8 @@ export class ComponentCreatorInterface {
}
/**
*
* @param {JSON} doc
* Create a $element to render the full doc
* @param {Object} doc
* @returns {$element}
*/
static create$item(doc) {
@ -17,11 +21,10 @@ export class ComponentCreatorInterface {
}
/**
*
* @param {JSON} candidate
* @returns {boolean}
* @param {Object} candidate
* @returns {boolean}
*/
static canCreate(candidate) {
throw 'Not Implemented';
}
}
}

View File

@ -1,6 +1,10 @@
import { NodesBase } from "./NodesBase";
import { thenLoadVideoProgress } from '../utils';
/**
* Create $element from a node of type asset
* @deprecated use vue instead
*/
export class Assets extends NodesBase{
static create$listItem(node) {
var markIfPublic = true;

View File

@ -3,6 +3,10 @@ import { ComponentCreatorInterface } from '../component/ComponentCreatorInterfac
let CREATE_NODE_ITEM_MAP = {}
/**
* Create $element from node object
* @deprecated use vue instead
*/
export class Nodes extends ComponentCreatorInterface {
/**
* Creates a small list item out of a node document
@ -37,7 +41,7 @@ export class Nodes extends ComponentCreatorInterface {
let $link = $('<a>')
.addClass('btn btn-outline-primary px-5 mb-auto btn-block js-load-next')
.attr('href', 'javascript:void(0);')
.click((e)=> {
.click((e)=> {
let $target = $(e.target);
$target.replaceWith(Nodes.createListOf$nodeItems(nodesLeftToRender, loadNext, loadNext));
})
@ -60,4 +64,4 @@ export class Nodes extends ComponentCreatorInterface {
static registerTemplate(node_type, klass) {
CREATE_NODE_ITEM_MAP[node_type] = klass;
}
}
}

View File

@ -1,6 +1,9 @@
import { prettyDate } from '../../utils/prettydate';
import { ComponentCreatorInterface } from '../component/ComponentCreatorInterface'
/**
* @deprecated use vue instead
*/
export class NodesBase extends ComponentCreatorInterface {
static create$listItem(node) {
let nid = (node._id || node.objectID); // To support both mongo and elastic nodes

View File

@ -1,5 +1,9 @@
import { NodesBase } from "./NodesBase";
/**
* Create $element from a node of type post
* @deprecated use vue instead
*/
export class Posts extends NodesBase {
static create$item(post) {
let content = [];

View File

@ -1,5 +1,9 @@
import { ComponentCreatorInterface } from '../component/ComponentCreatorInterface'
/**
* Create $elements from user objects
* @deprecated use vue instead
*/
export class Users extends ComponentCreatorInterface {
static create$listItem(userDoc) {
let roles = userDoc.roles || [];