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

feat: default edit menu #4

Merged
merged 3 commits into from
Jun 22, 2022
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ export default {
"Saturday",
"Sunday",
],
colors: [ // list of event's possible colors
"#F44336",
"#FF9800",
"#FFEB3B",
"#8BC34A",
"#4CAF50",
"#00BCD4",
"#2196F3",
],
inputType: "text" // usually set as text or number
}
```

Expand Down
59 changes: 0 additions & 59 deletions dev/serve.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,59 +29,11 @@
</p>
</v-col>
<vuetify-week-scheduler
@edit="onEdit"
v-model="events"
:config="config"
:editable="editable"
/>
</v-container>

<v-dialog
v-model="editDialog"
persistent
v-if="editEvent"
max-width="400px"
>
<v-card>
<v-card-title>
<span class="text-h5">Edit event</span>
</v-card-title>
<v-card-text>
<v-container>
<v-row>
<v-col cols="12">
<v-text-field
label="Title"
required
v-model="editEvent.title"
></v-text-field>
</v-col>

<v-col cols="12">
<v-icon
:color="c"
:style="{
border:
editEvent.backgroundColor === c ? '1px solid #ccc' : '',
}"
v-for="c in colors"
:key="c"
@click="editEvent.backgroundColor = c"
size="50px"
>mdi-square</v-icon
>
</v-col>
</v-row>
</v-container>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="blue darken-1" text @click="editDialog = false">
Close
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-footer fixed>
<v-spacer></v-spacer>
<div>Innovation System &copy; {{ new Date().getFullYear() }}</div>
Expand Down Expand Up @@ -109,19 +61,8 @@ export default Vue.extend({
periodTextColor: "#fff",
periodBorderColor: "#ccc",
},
editDialog: false,
editEvent: null,
colors: ["#F44336", "#3F51B5", "#9C27B0", "#FF9800", "#4CAF50", "#FFEB3B"],
}),
methods: {
onEdit(e) {
const { day, index } = e;

const { periods } = this.events[day];
this.editEvent = periods[index];

this.editDialog = true;
},
openGithub() {
window.open(
"https://github.com/innovation-system/vuetify-week-scheduler",
Expand Down
2 changes: 1 addition & 1 deletion src/vuetify-week-scheduler-period.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class="vws-period"
@mousedown.stop="$emit('period-drag', $event)"
@touchstart.stop="$emit('period-drag', $event)"
@contextmenu.stop.prevent="$emit('edit')"
@contextmenu.stop.prevent="$emit('edit', $event)"
@dblclick.stop.prevent="$emit('edit')"
:style="{
backgroundColor: options.backgroundColor,
Expand Down
66 changes: 63 additions & 3 deletions src/vuetify-week-scheduler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@position-change="onPositionChange(day.day, p.index, $event)"
@delete="deletePeriod(day.day, p.index)"
@clone="clonePeriod(day.day, p.index)"
@edit="editPeriod(day.day, p.index)"
@edit="editPeriod(day.day, p.index, $event)"
></scheduler-period>

<div
Expand Down Expand Up @@ -80,6 +80,41 @@
<div class="vws-grid-hour">{{ formatHour(n - 1) }}</div>
</div>
</div>
<v-menu
v-if="showEditMenu"
v-model="showEditMenu"
:position-x="x"
:position-y="y"
absolute
offset-y
:close-on-content-click="false"
>
<v-list dense>
<v-list-item>
<v-text-field
label="Title"
required
v-model="editEvent.title"
:type="settings.inputType"
></v-text-field>
</v-list-item>
<v-list-item class="d-flex" style="max-width: 300px">
<v-btn
icon
v-for="c in settings.colors"
:key="c"
:elevation="editEvent.backgroundColor === c ? 10 : 0"
>
<v-icon
:color="c"
@click="editEvent.backgroundColor = c"
size="35px"
>mdi-circle</v-icon
>
</v-btn>
</v-list-item>
</v-list>
</v-menu>
</div>
</template>

Expand Down Expand Up @@ -107,6 +142,10 @@ export default {
newPeriod: null,
draggingPeriod: null,
resizingPeriod: null,
showEditMenu: false,
x: 0,
y: 0,
editEvent: null,
};
},
mounted() {
Expand Down Expand Up @@ -184,6 +223,7 @@ export default {
periodTextColor: "#000",
periodRemoveButton: "Remove",
periodDuplicateButton: "Duplicate",
inputType: "text",
daysList: [
"Monday",
"Tuesday",
Expand All @@ -193,6 +233,15 @@ export default {
"Saturday",
"Sunday",
],
colors: [
"#F44336",
"#FF9800",
"#FFEB3B",
"#8BC34A",
"#4CAF50",
"#00BCD4",
"#2196F3",
],
};
},
/** When clicking on a day */
Expand Down Expand Up @@ -635,9 +684,20 @@ export default {

element.addEventListener(event, callback, options);
},
async editPeriod(day, index) {
async editPeriod(day, index, e) {
if (this.editable) {
this.$emit("edit", { day, index });
if (this.$listeners.edit) {
this.$emit("edit", { day, index });
} else {
e.preventDefault();
this.showEditMenu = false;
this.x = e.clientX;
this.y = e.clientY;
const { periods } = this.value[day];
this.editEvent = periods[index];
await this.$nextTick();
this.showEditMenu = true;
}
}
},
getY(e, prevent) {
Expand Down