/
collectionView.js
220 lines (201 loc) · 5.23 KB
/
collectionView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import React, {Component, PropTypes} from 'react'
import CollectionStore from '../../../stores/collectionStore'
import CrawlStore from '../../../stores/crawlStore'
import {ipcRenderer as ipc, remote} from 'electron'
import path from 'path'
import {joinStrings} from 'joinable'
import BeamMeUpScotty from 'drag-drop'
import * as notify from '../../../actions/notification-actions'
import {memoize} from 'lodash'
import S from 'string'
import shallowCompare from 'react-addons-shallow-compare'
import CollectionTabs from './collectionTabs'
import wailConstants from '../../../constants/wail-constants'
import CollectionActions from '../util/collectionActions'
// From https://github.com/oliviertassinari/react-swipeable-views
const EventTypes = wailConstants.EventTypes
S.TMPL_OPEN = '{'
S.TMPL_CLOSE = '}'
const metadataTransform = (mdata) => {
if (mdata) {
let tmdata = {}
mdata.forEach(md => {
tmdata[ md.k ] = md.v
})
return tmdata
} else {
return mdata
}
}
const styles = {
headline: {
fontSize: 24,
paddingTop: 16,
marginBottom: 12,
fontWeight: 400
},
slide: {
padding: 10
}
}
const runsToMap = runs => {
let len = runs.length
let runMap = new Map()
for (let i = 0; i < len; ++i) {
}
}
export default class CollectionView extends Component {
static contextTypes = {
muiTheme: PropTypes.object.isRequired
}
static childContextTypes = {
viewingCol: PropTypes.string.isRequired
}
constructor (...args) {
super(...args)
this.removeWarcAdder = null
}
// @decorate(memoize)
makeChildContext (col) {
let viewingCol = CollectionStore.getCollection(col)
let viewingColRuns = CrawlStore.getCrawlsForCol(col)
let uniqueSeeds = new Set()
let runMap = new Map()
let len = viewingColRuns.length
let totalCrawls = 0
for (let i = 0; i < len; ++i) {
if (Array.isArray(viewingColRuns[i].urls)) {
viewingColRuns[i].urls.forEach(url => {
if (!uniqueSeeds.has(url)) {
uniqueSeeds.add(url)
runMap.set(url, viewingColRuns[i])
}
})
} else {
if (!uniqueSeeds.has(viewingColRuns[i].urls)) {
uniqueSeeds.add(viewingColRuns[i].urls)
runMap.set(viewingColRuns[i].urls, viewingColRuns[i])
}
}
totalCrawls += viewingColRuns[i].runs.length
}
return {
forCol: this.props.params.col
}
}
getChildContext () {
console.log('collectionView getChildContext')
return {
viewingCol: this.props.params.col
}
}
shouldComponentUpdate (nextProps, nextState, nextContext) {
return shallowCompare(this, nextProps, nextState)
}
componentDidMount () {
if (!this.removeWarcAdder) {
console.log('attaching warc adder on live dom')
this.removeWarcAdder = BeamMeUpScotty('#warcUpload', (files) => {
console.log(`adding warcs maybe to col ${this.props.params.col}`, files)
let addMe = []
let badFiles = new Set()
files.forEach(f => {
console.log(f)
let ext = path.extname(f.path)
if (ext === '.warc' || ext === '.arc') {
addMe.push(f.path)
} else {
badFiles.add(ext)
}
})
if (badFiles.size > 0) {
notify.notifyWarning(`Unable to add files with extensions of ${joinStrings(...badFiles, { separator: ',' })}`)
}
if (addMe.length > 0) {
notify.notifyInfo(`Adding ${addMe.length} ${path.extname(addMe[ 0 ])} Files`, true)
ipc.send('add-warcs-to-col', {
forCol: this.props.params.col,
warcs: joinStrings(...addMe, { separator: ' ' })
})
}
})
} else {
console.log('we mounted but already have the warc upload listener attached')
}
}
componentWillUnmount () {
this.removeWarcAdder()
this.removeWarcAdder = null
}
render () {
console.log('colview')
return (
<div id='warcUpload' style={{ width: '100%', height: '100%' }}>
<CollectionTabs />
<CollectionActions />
</div>
)
}
}
/*
<Card>
<CardTitle
title={metadata['title']}
children={<NumArchives viewingCol={this.props.params.col} numArchives={numArchives}/>}
/>
<ReactTooltip/>
</Card>
<Menu
direction="horizontal"
distance={80}
width={50}
height={50}
y={100}
x={100}
customStyle={{
color: primary1Color,
textAlign: 'center',
lineHeight: '60px',
backgroundColor: primary1Color,
border: `solid 1px ${primary1Color}`,
borderRadius: '50%'
}}>
<div >
<Apps onTouchTap={() => console.log('clicked')}/>
</div>
<Home />
<Adb/>
</Menu>
let viewingCol = CollectionStore.getCollection(this.props.viewingCol)
let tmdata = metadataTransform(viewingCol.metadata)
<div>
<Grid fluid>
<Row between="xs">
{
tmdata[ 'title' ] &&
<Col xs>
<p>{`Title: ${tmdata[ 'title' ]}`}</p>
</Col>
}
{
tmdata[ 'description' ] &&
<Col xs>
<p>{`Description: ${tmdata[ 'description' ]}`}</p>
</Col>
}
<Col xs>
<NumArchives viewingCol={this.props.viewingCol}/>
</Col>
</Row>
<Row>
<Col xs>
<CollectionCrawls height={this.props.height} viewingCol={this.props.viewingCol}/>
</Col>
<Col xs>
<CollectionSearch height={this.props.height} viewingCol={this.props.viewingCol}/>
</Col>
</Row>
</Grid>
<ReactTooltip/>
</div>
*/