Skip to content
This repository has been archived by the owner on Apr 30, 2020. It is now read-only.

Commit

Permalink
Revert "Code review and clean up"
Browse files Browse the repository at this point in the history
  • Loading branch information
zuoyuanh committed Jul 27, 2018
1 parent 57194eb commit a89e1ec
Show file tree
Hide file tree
Showing 18 changed files with 521 additions and 598 deletions.
3 changes: 0 additions & 3 deletions .prettierrc

This file was deleted.

28 changes: 5 additions & 23 deletions README.md
@@ -1,48 +1,30 @@
# jupyterlab-celltags

[![Binder](https://beta.mybinder.org/badge.svg)](https://mybinder.org/v2/gh/jupyterlab/jupyterlab-celltags/master?urlpath=lab)

A JupyterLab extension for notebook cell tags

## Prerequisites

* JupyterLab

## Install
## Installation

```bash
jupyter labextension install jupyterlab-celltags
```

## Development

### Contributing

If you would like to contribute to the project, please read our [contributor documentation](https://github.com/jupyterlab/jupyterlab/blob/master/CONTRIBUTING.md).

JupyterLab follows the official [Jupyter Code of Conduct](https://github.com/jupyter/governance/blob/master/conduct/code_of_conduct.md).

### Install

Requires node 4+ and npm 4+
For a development install (requires npm version 4 or later), do the following in the repository directory:

```bash
# Clone the repo to your local environment
git clone https://github.com/jupyterlab/jupyterlab-celltags.git
cd jupyterlab-shortcelltagscutui
# Install dependencies
npm install # or yarn
# Build Typescript source
npm run build # or yarn build
# Link your development version of the extension with JupyterLab
npm install
npm run build
jupyter labextension link .
# Rebuild Typescript source after making changes
npm run build # or yarn build
```

To rebuild the package and the JupyterLab app:

```bash
npm run build
jupyter lab build
```
```
5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -27,7 +27,6 @@
"scripts": {
"build": "tsc",
"clean": "rimraf lib",
"prettier": "prettier --write '{,src/*,src/**/*,style/*}{.js,.jsx,.ts,.tsx,.css,.json,.md}'",
"watch": "tsc -w"
},
"husky": {
Expand All @@ -46,12 +45,12 @@
"@jupyterlab/apputils": "^0.17.0-0",
"@jupyterlab/notebook": "^0.17.0-0",
"@jupyterlab/notebook-extension": "^0.17.0-0",
"@types/node": "^10.5.1",
"@types/react-dom": "^16.0.6",
"react": "~16.4.0",
"typestyle": "^2.0.1"
},
"devDependencies": {
"@types/node": "^10.5.1",
"@types/react-dom": "~16.0.2",
"husky": "^1.0.0-rc.13",
"lint-staged": "^7.2.0",
"prettier": "^1.13.7",
Expand Down
3 changes: 0 additions & 3 deletions postBuild

This file was deleted.

53 changes: 29 additions & 24 deletions src/components/celltags.ts
@@ -1,40 +1,44 @@
import { Cell } from '@jupyterlab/cells';
import {
Cell
} from '@jupyterlab/cells';

export function write_tag(cell: Cell, name: string, add: boolean) {
export
function write_tag(cell: Cell, name:string, add:boolean) {
/* If add = true, check if tags are undefined; if so, initialize the array.
Otherwise, check if the tag already exists; if so, return false.
Then add the tag to metadata.tags. */
if (name === '') {
if (name === "") {
//do nothing if tag is a blank string - can't add or remove
return;
} else if (add) {
// Add to metadata
let wtaglist = cell.model.metadata.get('tags') as string[];
let wtaglist = <string[]>cell.model.metadata.get('tags');
let new_tags = preprocess_input(name);
if (wtaglist === undefined) {
wtaglist = [];
var arr : string[] = [];
wtaglist = arr;
} else {
if (new_tags.length === 1 && wtaglist.indexOf(new_tags[0]) !== -1) {
return false;
}
}
const to_add: string[] = [];
for (let tag = 0; tag < new_tags.length; tag++) {
if (new_tags[tag] !== '' && !contains_tag(new_tags[tag], to_add)) {
var to_add: string[] = [];
for (var tag=0; tag<new_tags.length; tag++){
if (new_tags[tag] !== "" && !contains_tag(new_tags[tag], to_add)) {
to_add.push(new_tags[tag]);
}
}
const new_list: string[] = [];
for (let i = 0; i < wtaglist.length; i++) {
new_list.push(wtaglist[i]);
var new_list: string[] = [];
for (var i=0; i<wtaglist.length; i++) {
new_list.push(wtaglist[i]);
}
for (let j = 0; j < to_add.length; j++) {
for (var j=0; j<to_add.length; j++) {
if (!contains_tag(to_add[j], new_list)) {
new_list.push(to_add[j]);
new_list.push(to_add[j]);
}
}
cell.model.metadata.set('tags', new_list);
/* If add = false, try to remove from metadata. First check if metadata and
/* If add = false, try to remove from metadata. First check if metadata and
metadata.tags exist; if not, return false. Then remove the tag and remove
metadata.tags if it is empty.*/
} else {
Expand All @@ -44,28 +48,29 @@ export function write_tag(cell: Cell, name: string, add: boolean) {
return false;
}
// Remove tag from tags list
let rtaglist = cell.model.metadata.get('tags') as string[];
let rtaglist = <string[]>cell.model.metadata.get('tags');
var new_list: string[] = [];
for (var i = 0; i < rtaglist.length; i++) {
for (var i=0; i<rtaglist.length; i++) {
if (rtaglist[i] != name) {
new_list.push(rtaglist[i]);
}
}
cell.model.metadata.set('tags', new_list);
// If tags list is empty, remove it
let updated = cell.model.metadata.get('tags') as string[];
let updated = <string[]>cell.model.metadata.get('tags');
if (updated.length === 0) {
cell.model.metadata.delete('tags');
}
}
//cell.events.trigger('set_dirty.Notebook', {value: true});
return true;
}
};

export function preprocess_input(input: string) {
export
function preprocess_input(input:string) {
// Split on whitespace + commas:
return input.split(/[,\s]+/);
}
};

export
function cleanup_metadata(cell: Cell) {
Expand All @@ -74,9 +79,9 @@ function cleanup_metadata(cell: Cell) {
if (taglist === undefined) {
return;
}
for (let i = taglist.length - 1; i >= 0; i--) {
for (var i=taglist.length-1; i>=0; i--) {
var found = false;
for (let j = 0; j < i; j++) {
for (var j=0; j<i; j++) {
if (taglist[j] === taglist[i]) {
found = true;
break;
Expand All @@ -89,8 +94,8 @@ function cleanup_metadata(cell: Cell) {
cell.model.metadata.set('tags', results.reverse());
}

function contains_tag(tag: string, taglist: string[]) {
for (var i = 0; i < taglist.length; i++) {
function contains_tag(tag:string, taglist:string[]){
for (var i=0; i<taglist.length; i++) {
if (taglist[i] === tag) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/index.ts
@@ -1 +1 @@
export * from './tagstool';
export * from './tagstool';
6 changes: 2 additions & 4 deletions src/components/styles/index.ts
Expand Up @@ -3,9 +3,7 @@ import { TagListStyleClasses } from './tagslist-styles';
import { TagsToolStyleClasses } from './tagstool-styles';

const StyleClasses = {
TagStyleClasses,
TagListStyleClasses,
TagsToolStyleClasses
TagStyleClasses, TagListStyleClasses, TagsToolStyleClasses
};

export default StyleClasses;
export default StyleClasses;
22 changes: 14 additions & 8 deletions src/components/styles/shared-styles.ts
@@ -1,7 +1,9 @@
import * as React from 'react';

namespace SharedStyles {
export const tagInputStyleProperties = {

export
const tagInputStyleProperties = {
padding: '0px',
paddingBottom: '2px',
color: 'var(--jp-layout-color4)',
Expand All @@ -13,8 +15,9 @@ namespace SharedStyles {
backgroundColor: 'var(--jp-layout-color1)',
maxHeight: '30px'
} as React.CSSProperties;

export const tagStyleProperties = {

export
const tagStyleProperties = {
boxSizing: 'border-box',
borderRadius: '20px',
padding: '6px',
Expand All @@ -25,7 +28,8 @@ namespace SharedStyles {
maxWidth: 'calc(100% - 25px)'
} as React.CSSProperties;

export const confirmButtonProperties = {
export
const confirmButtonProperties = {
borderRadius: '3px',
backgroundColor: 'var(--jp-layout-color1)',
border: '1px solid #bdbdbd',
Expand All @@ -36,14 +40,16 @@ namespace SharedStyles {
paddingTop: '4px',
paddingBottom: '4px',
fontSize: '12px'
};
}

export const tagOperationsProperties = {
export
const tagOperationsProperties = {
padding: '5px',
paddingLeft: '10px',
fontSize: '13px',
width: '100%'
};
}

}

export default SharedStyles;
export default SharedStyles;
54 changes: 29 additions & 25 deletions src/components/styles/tag-styles.ts
@@ -1,61 +1,65 @@
import { style } from 'typestyle';
import SharedStyles from './shared-styles';

export namespace TagStyleClasses {
export const tagLabelStyleClass = style({
export
namespace TagStyleClasses {

export
const tagLabelStyleClass = style({
maxWidth: '100%',
textOverflow: 'ellipsis',
display: 'inline-block',
overflow: 'hidden',
boxSizing: 'border-box',
paddingRight: '25px'
});

export const defaultAddInputStyleClass = style(
SharedStyles.tagInputStyleProperties,
{
width: '64.52px',
minWidth: '64.52px'
}
);

export const blankAddInputStyleClass = style(
SharedStyles.tagInputStyleProperties,
{
display: 'inline',
whiteSpace: 'nowrap'
}
);

export const addTagStyleClass = style(SharedStyles.tagStyleProperties, {

export
const defaultAddInputStyleClass = style(SharedStyles.tagInputStyleProperties, {
width: '64.52px',
minWidth: '64.52px'
});

export
const blankAddInputStyleClass = style(SharedStyles.tagInputStyleProperties, {
display: 'inline',
whiteSpace: 'nowrap'
});

export
const addTagStyleClass = style(SharedStyles.tagStyleProperties, {
backgroundColor: 'var(--jp-layout-color1)',
border: '1px solid var(--jp-layout-color4)',
maxWidth: '95%',
maxHeight: '31px'
});

export const tagIconStyleClass = style({

export
const tagIconStyleClass = style({
marginLeft: '10px',
marginTop: '2px',
right: '0px',
marginBottom: '-1px',
height: '13px',
position: 'absolute'
});

export const inputIconStyleClass = style({

export
const inputIconStyleClass = style({
marginLeft: '5px',
marginTop: '1px',
marginBottom: '-2px',
height: '13px'
});

export const tagIconLabelStyleClass = style({
export
const tagIconLabelStyleClass = style({
position: 'absolute'
});

export
const addTagSpanStyleClass = style({

});

}

0 comments on commit a89e1ec

Please sign in to comment.