Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file picker #2

Merged
merged 1 commit into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> 1%
last 2 versions
not dead
22 changes: 22 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
root: true,
env: {
node: true
},
extends: ['plugin:vue/recommended', 'eslint:recommended', '@vue/prettier'],
parserOptions: {
parser: 'babel-eslint'
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
},
overrides: [
{
files: ['**/__tests__/*.{j,t}s?(x)', '**/tests/unit/**/*.spec.{j,t}s?(x)'],
env: {
jest: true
}
}
]
}
21 changes: 20 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
/hugo
**/l10n/locale
**/l10n/template.pot

/hugo

.idea

package-lock.json

node_modules
dist

*.log
.DS_Store
.envrc

public/file-picker-config.json
public/demo.html
public/file-picker.js
public/img
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 100,
"semi": false,
"singleQuote": true
}
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ownCloud File picker
Easily integrate ownCloud into your own web applications.

## Project setup
```
yarn install
```

### Compiles and hot-reloads for development
```
yarn serve
```

### Compiles and minifies for production
```
yarn build
```

### Run your unit tests
```
yarn test:unit
```

### Lints and fixes files
```
yarn lint
```
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@vue/cli-plugin-babel/preset']
}
6 changes: 6 additions & 0 deletions changelog/unreleased/file-picker
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Add basic implementation of file picker

We've added a basic implementation of ownCloud file picker.
File picker is a web component which can be integrated into existing products and is firing event providing array of selected resources

https://github.com/owncloud/file-picker/pull/2
8 changes: 8 additions & 0 deletions file-picker-config.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"server": "http://host.docker.internal:8080",
"auth" : {
"clientId": "EFB5Z5lBsFX4ejcRaCeSKAbn3171i09WpvSX5voC1iB2KwRzrrsZ3S3xnsPTWfrP",
"url": "http://host.docker.internal:8080/index.php/apps/oauth2/api/v1/token",
"authUrl": "http://host.docker.internal:8080/index.php/apps/oauth2/authorize"
}
}
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
preset: '@vue/cli-plugin-unit-jest'
}
38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "file-picker",
"version": "0.1.0",
"author": "ownclouders <[email protected]>",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build --target wc --name file-picker",
"test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.5",
"filesize": "^6.1.0",
"lodash": "^4.17.19",
"moment": "^2.27.0",
"oidc-client": "^1.10.1",
"owncloud-design-system": "^1.9.0",
"owncloud-sdk": "^1.0.0-728",
"path": "^0.12.7",
"vue": "^2.6.11",
"vue-virtual-scroller": "^1.0.10"
},
"devDependencies": {
"@babel/polyfill": "^7.10.4",
"@vue/cli-plugin-babel": "^4.4.0",
"@vue/cli-plugin-eslint": "^4.4.0",
"@vue/cli-plugin-unit-jest": "^4.4.0",
"@vue/cli-service": "^4.4.0",
"@vue/eslint-config-prettier": "^6.0.0",
"@vue/test-utils": "^1.0.3",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-vue": "^6.2.2",
"prettier": "^1.19.1",
"vue-template-compiler": "^2.6.11"
}
}
Binary file added public/favicon.ico
Binary file not shown.
17 changes: 17 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
25 changes: 25 additions & 0 deletions public/oidc-callback.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>Waiting...</title>
</head>

<body>
<script src="oidc-client.min.js"></script>
<script>

var mgr = new Oidc.UserManager({userStore: new Oidc.WebStorageStateStore(), loadUserInfo: true, filterProtocolClaims: true});

mgr.signinPopupCallback().then(function (user) {
console.log(user)
window.location.href = '../';
}).catch(function (err) {
console.log(err);
});

</script>
</body>

</html>
49 changes: 49 additions & 0 deletions public/oidc-client.min.js

Large diffs are not rendered by default.

128 changes: 128 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<template>
<div id="oc-file-picker" class="uk-height-1-1">
<div
v-if="state === 'loading'"
class="uk-height-1-1 uk-width-1-1 uk-flex uk-flex-middle uk-flex-center oc-border"
>
<oc-spinner aria-label="Loading ownCloud file picker" />
</div>
<login v-if="state === 'unauthorized'" key="login-form" @login="authenticate" />
<file-picker
v-if="state === 'authorized'"
key="file-picker"
class="uk-height-1-1"
:variation="variation"
@selectResources="selectResources"
/>
</div>
</template>

<script>
import Vue from 'vue'
import sdk from 'owncloud-sdk'
import DesignSystem from 'owncloud-design-system'
import initVueAuthenticate from './services/auth'
import FilePicker from './components/FilePicker.vue'
import Login from './components/Login.vue'
// Init sdk and design system
Vue.prototype.$client = new sdk()
Vue.use(DesignSystem)
export default {
name: 'App',
components: {
FilePicker,
Login
},
props: {
variation: {
type: String,
required: true,
validator: value => value === 'resource' || value === 'location'
},
configLocation: {
type: String,
required: false,
default: () => window.location.origin + '/file-picker-config.json'
}
},
data: () => ({
authInstance: null,
bearerToken: '',
state: 'loading',
config: null
}),
created() {
this.initAuthentication()
},
beforeDestroy() {
this.authInstance.mgr.events.removeUserLoaded()
},
methods: {
initApp() {
this.bearerToken = this.authInstance.getToken()
// Init owncloud-sdk
this.$client.init({
baseUrl: this.config.server,
auth: {
bearer: this.bearerToken
},
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
})
this.state = 'authorized'
return
},
async initAuthentication() {
let config = await fetch(this.configLocation)
this.config = await config.json()
this.authInstance = initVueAuthenticate(this.config)
this.checkUserAuthentication()
},
checkUserAuthentication() {
if (this.authInstance.isAuthenticated()) {
return this.initApp()
}
this.state = 'unauthorized'
LukasHirt marked this conversation as resolved.
Show resolved Hide resolved
// If the user is not authenticated, we add event listener when he logs in to automatically init the application afterwards
this.authInstance.mgr.events.addUserLoaded(() => {
this.initApp()
})
},
authenticate() {
this.authInstance.authenticate()
},
selectResources(resources) {
this.$emit('selectResources', resources)
}
}
}
</script>

<style>
/* Import oC CI font and design system styles */
@import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300;400;600;700&display=swap');
@import '../node_modules/owncloud-design-system/dist/system/system.css';
* {
font-family: 'Source Sans Pro', sans-serif;
}
</style>
Binary file added src/assets/img/background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading