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
  }
}
export function stations(state:Map<string,any> = Map<string,any>(), action:any):Map<string, List<StationModel>> {

    function indexOfStation(businessId, stationId):any {
        return stations.findIndex((i:StationModel) => {
            return i.getKey('businessId') === businessId && i.getKey('id') == stationId;
        });
    }

    switch (action.type) {
        case StationsAction.RECEIVE_STATIONS:
            return state.update(action.source, (value) => action.stations);

        case StationsAction.RECEIVE_STATIONS_GEO:
            for (var i in action.payload) {
                var station = action.payload[i];
                var source = station.source;
                var stations:List<StationModel> = state.get(source);
                stations = stations.update(indexOfStation(station.businessId, station.id), (i_station:StationModel) => {
                    return i_station.setKey<StationModel>(StationModel, 'geoLocation', {
                        lat: station.lat,
                        lon: station.lon,
                        city: station.city,
                        country: station.country
                    })
                });
                state = state.setIn([source], stations);
            }
            return state;
        default:
            return state;
    }
}
Example #3
0
    const renderGroupDeployNodes = (groupDeploys: List<DeployRecord>, deployGroup: DeployGroupRecord) => {
        const shouldShowProjectNames = !groupDeploys.equals(currentDeploys);

        return h(
            'li',
            { className: `deploy deploy--${deployGroup.status.split(' ').join('-').toLowerCase()}` },
            [
                h('h2', [
                    h('a', { href: createBuildLink(deployGroup.build) }, `${deployGroup.build}`)
                ]),
                // Only show project names if we have multiple deployed groups
                exp(shouldShowProjectNames) && ih('ul', {}, groupDeploys
                    .sortBy(build => build.projectName)
                    .map(deploy => {
                        const previousBuild = previousDeploysMap.get(deploy);
                        return h('li', [
                            h('a', {
                                href: createRiffRaffDeployLink(deploy.uuid),
                                title: previousBuild ? `Previous build: ${previousBuild.build}` : ''
                            }, deploy.projectName)
                        ]);
                    })
                    .toList()
                )
            ]
        );
    };
Example #4
0
  static FromXML(el: Element): [GF, undefined] | [undefined, Error] {
    const table: typeof GFDefaults = Object.assign({}, GFDefaults);
    let err: Error | undefined;

    for (let i = 0; i < el.attributes.length; i++) {
      const attr = el.attributes.item(i);
      if (!attr) {
        continue;
      }
      switch (attr.name.toLowerCase()) {
        case 'type':
          const kind = attr.value.toLowerCase();
          if (kind === 'discrete' || kind === 'continuous' || kind === 'extrapolate') {
            table.type = kind;
          } else {
            return [undefined, new Error(`bad GF type: ${kind}`)];
          }
          break;
      }
    }

    for (let i = 0; i < el.childNodes.length; i++) {
      const child = el.childNodes.item(i) as Element;
      if (child.nodeType !== 1) {
        // Element
        continue;
      }
      switch (child.nodeName.toLowerCase()) {
        case 'xscale':
          [table.xScale, err] = Scale.FromXML(child);
          if (err) {
            return [undefined, new Error(`xscale: ${err}`)];
          }
          break;
        case 'yscale':
          [table.yScale, err] = Scale.FromXML(child);
          if (err) {
            return [undefined, new Error(`yscale: ${err}`)];
          }
          break;
        case 'xpts':
          table.xPoints = numberize(splitOnComma(content(child)));
          break;
        case 'ypts':
          table.yPoints = numberize(splitOnComma(content(child)));
          break;
      }
    }

    if (table.yPoints === undefined) {
      return [undefined, new Error('table missing ypts')];
    }

    // FIXME: handle
    if (table.type && table.type !== 'continuous') {
      console.log('WARN: unimplemented table type: ' + table.type);
    }

    return [new GF(table), undefined];
  }
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;
}
Example #6
0
    updateActivityInMention(kind: TimelineActivityKind, status: Tweet, from: TwitterUser): [List<Item>, number] {
        const status_id = status.id;
        const index = this.mention.findIndex(item => {
            if (item instanceof TimelineActivity) {
                return item.kind === kind && item.status.id === status_id;
            } else {
                return false;
            }
        });

        const next_focus_index =
            this.kind === 'mention' && (index === -1 || index < this.focus_index) ?
                this.nextFocusIndex(this.mention.size + 1) : this.focus_index;

        if (index === -1) {
            return [this.mention.unshift(new TimelineActivity(kind, status, [from])), next_focus_index];
        } else {
            const will_updated = this.mention.get(index);
            if (will_updated instanceof TimelineActivity) {
                const updated = will_updated.update(status, from);
                return [this.mention.delete(index).unshift(updated), next_focus_index];
            } else {
                log.error('Invalid activity for update:', will_updated);
                return [this.mention, next_focus_index];
            }
        }
    }
Example #7
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 #8
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 #9
0
function updateStatusIn(items: List<Item>, status: Tweet) {
    'use strict';
    const status_id = status.id;
    const index = items.findIndex(item => {
        if (item instanceof Tweet) {
            return item.getMainStatus().id === status_id;
        } else {
            return false;
        }
    });

    if (index === -1) {
        return items;
    }

    return items.update(index, item => {
        if (item instanceof Tweet) {
            if (item.isRetweet()) {
                const cloned = item.clone();
                cloned.json.retweeted_status = status.json;
                return cloned;
            } else {
                return status;
            }
        } else {
            log.error('Never reaches here');
            return item;
        }
    });
}
Example #10
0
function getStageNameList(stageList: List<StageConfig | RawStageConfig>) {
  if (stageList.isEmpty()) {
    return 'empty'
  } else {
    return stageList.map(s => s.name).join(',')
  }
}