Example #1
1
function searchAnnotations(search: string|null, annotations: List<Record<AnnotationColorMap>>) {
  if(search !== null) {
    const jsAnnotations = annotations.toJS()
    const fuse = new Fuse(jsAnnotations, _FUSE_OPTIONS_)
    const res: string[] = fuse.search(search)
    return annotations.filter(ann => {
      const aId = ann.getIn(['annotation', 'id'])
      return res.find(id => parseInt(id) === aId)
    })
  } else {
    return annotations
  }
}
Example #2
0
    addNoRetweetUserIds(ids: number[]) {
        const predicate = (i: Item) => {
            if (i instanceof Tweet) {
                return !i.isRetweet() || ids.indexOf(i.retweeted_status.user.id) === -1;
            } else {
                return true;
            }
        };

        const next_home = this.home.filter(predicate).toList();
        const next_mention = this.mention.filter(predicate).toList();
        const next_no_retweet_ids = this.no_retweet_ids.merge(ids);

        // XXX:
        // Next focus index calculation is too complicated.  I skipped it.

        return new TimelineState(
            this.kind,
            next_home,
            next_mention,
            this.user,
            this.notified,
            this.rejected_ids,
            next_no_retweet_ids,
            this.focus_index
        );
    }
Example #3
0
    addRejectedIds(ids: number[]) {
        const will_added = ids.filter(id => !this.rejected_ids.contains(id));
        if (will_added.length === 0) {
            return this;
        }

        const predicate = (i: Item) => {
            if (i instanceof Tweet) {
                const id = i.getMainStatus().user.id;
                return will_added.indexOf(id) === -1;
            }
            return true;
        };

        const next_home = this.home.filter(predicate).toList();
        const next_mention = this.mention.filter(predicate).toList();
        const home_updated = next_home.size !== this.home.size;
        const mention_updated = next_mention.size !== this.mention.size;
        const next_rejected_ids = this.rejected_ids.merge(will_added);

        // XXX:
        // Next focus index calculation is too complicated.  I skipped it.

        return new TimelineState(
            this.kind,
            home_updated ? next_home : this.home,
            mention_updated ? next_mention : this.mention,
            this.user,
            this.notified,
            next_rejected_ids,
            this.no_retweet_ids,
            this.focus_index
        );
    }
Example #4
0
    removeNode(node: any) {
        var nodesAll = this.nodes.filter(n => n !== node).toList();
        var parentsAll: Map<number, List<Node>> = this.parents;
        var childrenAll: Map<number, List<Node>> = this.children;

        var parents = parentsAll.get(node.id);

        parents.forEach((parent) => {
            var children = childrenAll.get(parent.id);
            children = children.filter((child) => child !== node).toList();
            childrenAll = childrenAll.set(parent.id, children);
        });
        parentsAll = parentsAll.set(node.id, List<any>());

        var children = childrenAll.get(node.id);

        children.forEach((child) => {
            var parents = parentsAll.get(child.id);
            parents = parents.filter((ancestor) => ancestor !== node).toList();
            parentsAll = parentsAll.set(child.id, parents);
        });

        childrenAll = childrenAll.remove(node.id);

        return new Graph(nodesAll, childrenAll, parentsAll);
    }
Example #5
0
export function reducer(state: List<SettingItem> = List<SettingItem>(), action: ITodoAction) {

  function indexOf(uuid: string) {
    return state.findIndex((i: SettingItem) => i.uuid === action.itemId);
  }

  function createItemObj(text: string) {
    if (!text) {
      return new SettingItem();
    }
    if (text.indexOf('|') >= 0) {
      // parse the text for name|value format
      let tokens = text.split('|');
      if (tokens.length > 1) {
        return new SettingItem({name: tokens[0], value: tokens[1], completed: false, uuid: uuid.v4()});
      }
    }
    return new SettingItem({name: '[no name]', value: text, completed: false, uuid: uuid.v4()});
  }

  switch (action.type) {
    case 'ADD':
      return state.push(createItemObj(action.text));
    case 'REMOVE':
      return List<SettingItem>(state.filter((i: SettingItem) => i.uuid !== action.itemId));
    case 'UPDATE_ITEM_VALUE':
      return state.update(indexOf(action.itemId), (i: SettingItem) => i.setValue(action.text));
    case 'UPDATE_ITEM_COMPLETION':
      return state.update(indexOf(action.itemId), (i: SettingItem) => i.setCompleted(action.completed));
    default:
      return state;
  }

}
Example #6
0
    getNodes(filter: (node: any) => boolean) {
        if (!filter) {
            return this.nodes;
        }

        return this.nodes.filter(filter);
    }
function todosReducer(state:List<ITask>, action:IAction):List<ITask> {
        console.log(`todosReducer: Action(${JSON.stringify(action)})`);
        switch(action.type) {
                case Keys.AddTodo:
                    var todos: List<ITask> = List<ITask>(state.concat([action.payload]));
                    console.log(`todosReducer: todos(${JSON.stringify(todos)})`);
                    return todos;
                case Keys.CompleteTodo:
                        return List<ITask>(state.map((task:ITask) => {
                                if (task.Id === action.payload.Id) {
                                        return new Task(
                                                task.Id,
                                                task.Title,
                                                task.Description,
                                                action.payload.Complete
                                        );
                                } else {
                                        return task;
                                }
                        }));
                case Keys.RemoveTodo:
                        return List<ITask>(state.filter((task:ITask) => {
                                return task.Id !== action.payload.Id;
                        }))
        }                                 
        return state || initialState.todos;
}
 @Input()
 set showOption(i_value: 'url' | 'page') {
     this.m_mode = i_value;
     if (i_value == 'url') {
         this.m_actions = this.m_actions.filter((v: StoreModel) => {
             return v.getKey('name') != 'selectPage';
         }) as List<any>;
         return;
     }
     if (i_value == 'page') {
         this.m_actions = this.m_actions.filter((v: StoreModel) => {
             return v.getKey('name') != 'loadUrl';
         }) as List<any>;
         return;
     }
 }
Example #9
0
export function adnet(state: Map<string,any> = Map<string,any>(), action: any): Map<string,any> {

    var indexOfRateId = function (i_rateId: string) {
        return rates.findIndex((i: AdnetRateModel) => i.rateId() === i_rateId);
    }
    var indexOfCustomerId = function (i_adnetCustomerId: string) {
        return customers.findIndex((i: AdnetCustomerModel) => i.customerId() === i_adnetCustomerId);
    }
    switch (action.type) {
        case AdnetActions.RECEIVE_CUSTOMERS: {
            return state.setIn(['customers'], action.customers);
        }
        case AdnetActions.RECEIVE_RATES: {
            return state.setIn(['rates'], action.rates);
        }
        case AdnetActions.UPDATE_ADNET_RATE_TABLE: {
            var rates: List<AdnetRateModel> = state.getIn(['rates']);

            rates = rates.update(indexOfRateId(action.payload.rateId), (rate: AdnetRateModel) => {
                return rate.setField('rateMap', action.payload.rateTable)
            });
            rates = rates.update(indexOfRateId(action.payload.rateId), (rate: AdnetRateModel) => {
                rate = rate.setField('hourRate0', action.payload.adHourlyRate["0"])
                rate = rate.setField('hourRate1', action.payload.adHourlyRate["1"])
                rate = rate.setField('hourRate2', action.payload.adHourlyRate["2"])
                rate = rate.setField('hourRate3', action.payload.adHourlyRate["3"])
                return rate;
            });
            return state.setIn(['rates'], rates);
        }
        case AdnetActions.ADD_ADNET_RATE_TABLE: {
            var rates: List<AdnetRateModel> = state.getIn(['rates']);
            rates = rates.push(action.adnetRateModel);
            return state.setIn(['rates'], rates);
        }
        case AdnetActions.REMOVE_ADNET_RATE_TABLE: {
            var rates: List<AdnetRateModel> = state.getIn(['rates']);
            var updatedRates:List<AdnetRateModel> = rates.filter((adnetRateModel:AdnetRateModel) => adnetRateModel.rateId() !== action.rateId) as List<AdnetRateModel>;
            return state.setIn(['rates'], updatedRates);
        }
        case AdnetActions.UPDATE_ADNET_CUSTOMER: {
            var customers: List<AdnetCustomerModel> = state.getIn(['customers'])
            customers = customers.update(indexOfCustomerId(action.payload.Key), (customer: AdnetCustomerModel) => {
                return customer.setData<AdnetCustomerModel>(AdnetCustomerModel, action.payload)
            });
            return state.setIn(['customers'], customers);
        }
        case AdnetActions.RENAME_ADNET_RATE_TABLE: {
            var rates: List<AdnetRateModel> = state.getIn(['rates']);
            rates = rates.update(indexOfRateId(action.payload.rateId), (rate: AdnetRateModel) => {
                return rate.setField('label', action.payload.newLabel)
            });
            return state.setIn(['rates'], rates);
        }
        default:
            return state;
    }
}
 transform(value: List<Transaction>, target){
     if(value == null){
         return null;
     }
     
     return value.filter(t => {
         return this.compareTransaction(target, t);
     }).slice(0, 15);
 }