summaryrefslogtreecommitdiff
path: root/app/client/modules/samplernn/views/samplernn.import.js
blob: 653d9301a02f09dfd403ff50158db425807dbefa (plain)
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
import { h, Component } from 'preact'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import util from '../../../util'

import * as samplernnActions from '../samplernn.actions'

import Select from '../../../common/select.component'
import TextInput from '../../../common/textInput.component'
import Button from '../../../common/button.component'

import DatasetComponent from '../../../dataset/dataset.component'

const samplernnModule = {
  name: 'samplernn',
  datatype: 'audio',
}

class SampleRNNImport extends Component {
  constructor(){
    super()
    this.state = {
      folder: 1,
      import_action: 'Hotlink',
      url_base: 'https://s3.amazonaws.com/i.asdf.us/bucky/data/4279/',
      selected: {},
    }
  }
  componentWillMount(){
    const id = this.props.match.params.id || localStorage.getItem('samplernn.last_id')
    console.log('load dataset:', id)
    const { match, samplernn, samplernnActions } = this.props
    if (id === 'new') return
    if (id) {
      if (parseInt(id)) localStorage.setItem('samplernn.last_id', id)
      if (! samplernn.folder || samplernn.folder.id !== id) {
        this.props.actions.load_directories(id)
      }
    }
  }
  render(){
    const { samplernn } = this.props
    let datasets = [], folder;
    if (this.props.samplernn.data) {
      datasets = (this.props.samplernn.data.folders || []).map(folder => {
        return [folder.name, folder.id]
      })
      folder = this.props.samplernn.data.folderLookup.unsorted
    }
    return (
      <div className='app top'>
        <div class='heading'>
          <h1>Import</h1>
        </div>
        <div class='params form row datasets'>
          <div class='row dataset'>
            <div class='col'>
            </div>
            <div class='col'>
            </div>
            <div class='col'>
            </div>
            <div class='col'>
              <h2>Import to dataset</h2>
              <Select
                title='Destination dataset'
                options={datasets}
                name='folder'
                opt={this.state}
                onChange={(name, value) => this.setState({ folder: value })}
              />
              <Select
                title='Import action'
                options={['Hotlink', 'Upload']}
                name='import_action'
                opt={this.state}
                onChange={(name, value) => this.setState({ import_action: value })}
              />
              <TextInput
                title="Remote URL base"
                value={this.state.url_base}
                placeholder="http://"
                onSave={(value) => this.setState({ url_base: value })}
              />
              <Button
                title=""
                onClick={() => this.doImport()}
              >
                Import
              </Button>
            </div>
          </div>
        </div>
        <DatasetComponent
          loading={samplernn.loading}
          progress={samplernn.progress}
          module={samplernnModule}
          data={samplernn.data}
          id="unsorted"
          folder={folder}
          history={this.props.history}
          onPickDataset={(dataset => this.toggle(dataset.name, this.state.selected[name]))}
          beforeRow={dataset => this.beforeRow(dataset)}
          afterRow={dataset => this.afterRow(dataset)}
        />
      </div>
    )
  }
  toggle(name){
    this.setState({
      ...this.state,
      selected: {
        ...this.state.selected,
        [name]: !this.state.selected[name],
      }
    })
  }
  beforeRow(dataset){
    // console.log(dataset)
  }
  afterRow(dataset){
    const name = dataset.name
    return (
      <div>
        <input
          type="checkbox"
          value={name}
          checked={!!this.state.selected[name]}
        />
      </div>
    )
  }
  doImport(){
    const { samplernn } = this.props
    console.log(this.state)
    this.props.actions.import_files(this.state, samplernn.data.datasetLookup, samplernn.data.fileLookup)
  }
}

const mapStateToProps = state => ({
  samplernn: state.module.samplernn,
  runner: state.system.runner,
  task: state.task,
})

const mapDispatchToProps = (dispatch, ownProps) => ({
  actions: bindActionCreators(samplernnActions, dispatch),
})

export default connect(mapStateToProps, mapDispatchToProps)(SampleRNNImport)